当我想用XPath打印evaluate表达式的结果时,我有错误.
$ url = $ xpath-> evaluate('// a/@ href',$ event); echo $ url;
我有这个错误:可捕获的致命错误:类DOMNodeList的对象无法转换为字符串
我的代码:
<?php
// Get the HTML Source Code
$url='http://www.parisbouge.com/events/2012/05/01/';
$source = file_get_contents($url);
// DOM document Creation
$doc = new DOMDocument;
$doc->loadHTML($source);
// DOM XPath Creation
$xpath = new DOMXPath($doc);
// Get all events
$events = $xpath->query('//li[@class="nom"]');
// Count number of events
printf('There is %d events<br />', $events->length);
// List all events
for($i = 0; $i < ($events->length); $i++) {
$event = $events->item($i);
$url = $xpath->evaluate('//a/@href', …Run Code Online (Sandbox Code Playgroud) 我有一个VPS(Debian,Apache,MySQL,PHP)
我想强制UTF-8编码.我把这一行:
header('Content-type: application/json; charset: UTF-8');
Run Code Online (Sandbox Code Playgroud)
但是charset仍然是ISO8859
我还编辑了php.ini:/etc/php5/apache2/php.ini
mbstring.language=UTF-8
mbstring.internal_encoding= UTF-8
mbstring.http_input=UTF-8
mbstring.http_output=UTF-8
mbstring.detect_order= auto
Run Code Online (Sandbox Code Playgroud)
和apache conf:
nano /etc/apache2/conf.d/charset
AddDefaultCharset UTF-8
Run Code Online (Sandbox Code Playgroud)
iOS应用程序正在调用我的php页面.我给它一个JSON输出.但它收到了ISO charset ......
我想用PHP解析这个URL以获得特定地址的纬度(2 + bis + avenue + Foch75116 + Paris + FR):
我使用谷歌地图网络服务:http://maps.googleapis.com/maps/api/geocode/json?address = 2 + bis + avenue + Foch75116 + Paris + FR&_sensor = false
// Get the JSON
$url='http://maps.googleapis.com/maps/api/geocode/json?address=2+bis+avenue+Foch75116+Paris+FR&sensor=false';
$source = file_get_contents($url);
$obj = json_decode($source);
var_dump($obj);
Run Code Online (Sandbox Code Playgroud)
它不起作用.我有这个错误:
OVER_QUERY_LIMIT
所以我在网上搜索,我发现使用谷歌地图api有限制(2个查询之间最少1秒,每天最多2500个查询)
你知道如何将地址转换为 - >纬度/经度???
我想替换这个URI
http://localhost/prixou/index.php?page=list&category=1&sub=1&subsub=0&brand=Sony&toto=titi
Run Code Online (Sandbox Code Playgroud)
通过这个URI
http://localhost/prixou/index.php?page=list&category=1&sub=1&subsub=0&kljklj=sdfsd
Run Code Online (Sandbox Code Playgroud)
==>我想删除"&brand = Sony"
我试过这个:
preg_replace('/(^.*)(&brand=.*)(&.*)/', '$1$3', 'http://localhost/prixou/index.php?page=list&category=1&sub=1&subsub=0&brand=Sony&toto=titi');
Run Code Online (Sandbox Code Playgroud)
但它在特定情况下不起作用:URI中的参数"toto"不存在的情况
所以,如果我这样做
preg_replace('/(^.*)(&brand=.*)(&.*)/', '$1$3', 'http://localhost/prixou/index.php?page=list&category=1&sub=1&subsub=0&brand=Sony');
Run Code Online (Sandbox Code Playgroud)
它不起作用==>"&brand = Sony"仍然出现
那我该怎么办?
php ×4
apache ×1
debian ×1
domdocument ×1
domxpath ×1
encoding ×1
evaluate ×1
json ×1
maps ×1
preg-replace ×1
utf-8 ×1
web-services ×1
xpath ×1