xpath dom preg_match
I have this code with google map coordinates inside and i try to get coordinates but somewhere is a problem; The code is:
<iframe width="430" scrolling="no" height="250" frameborder="0" src="http://maps.google.cz/maps/ms?msa=0&hl=cs&brcurrent=5,0,0&ie=UTF8&vpsrc=6&msid=207589766138527801127.0004aadb2c99231cecabd&ll=44.782627,20.48152&spn=0.003808,0.009205&z=16&output=embed" marginwidth="0" marginheight="0"/>
and i try to get coordinates with this code:
$string = curl($e->textContent);
preg_match('#&ll=(.*?)&#is', $string, $matches);
list($lat, $lng) = explode(',', $matches[1]);
$data['lat'] = $lat;
$data['lng'] = $lng;
but dont work!
WHERE IS THE PROBLEM? WHERE I WRONG! (sorry for english)
This is my full code, but dont work:
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
libxml_use_internal_errors(true);
$dom = new DOMDocument();
@$dom->loadHTMLFile('http://www.kupoman.rs/aktivne-ponude/');
$xpath = new DOMXPath($dom);
$entries = $xpath->query("//div[@class='dealcontent']/h1/a/@href");
$output = array();
$i = 1;
foreach($entries as $e) { 开发者_开发问答
$dom2 = new DOMDocument();
@$dom2->loadHTMLFile($e->textContent);
$xpath2 = new DOMXPath($dom2);
$data = array();
$string = $xpath2->query("//iframe/@src")->item(0)->textContent;
$data['link']= ($e->textContent);
$data['naslov'] = trim($xpath2->query("//div[@class='dealcontent']/h1")->item(0)->textContent);
$data['slika'] = trim($xpath2->query("//div[@class='slideshow']/img[1]/@src")->item(0)->textContent);
preg_match('/.*&ll=([\d.,]+)&.*/', $string, $matches);
list($lat, $lng) = explode(',', $matches[1]);
$data['lat'] = $lat;
$data['lng'] = $lng;
all is good but coordinates is 0,0 :(
There's a lot wrong. There's no xpath expression, your regex is wrong and you are calling curl for some reason. Maybe you're trying to do something like this:
$dom = new DOMDocument();
@$dom->loadHTML('<iframe width="430" scrolling="no" height="250" frameborder="0" src="http://maps.google.cz/maps/ms?msa=0&hl=cs&brcurrent=5,0,0&ie=UTF8&vpsrc=6&msid=207589766138527801127.0004aadb2c99231cecabd&ll=44.782627,20.48152&spn=0.003808,0.009205&z=16&output=embed" marginwidth="0" marginheight="0"/>');
$xpath = new DOMXPath($dom);
$string = $xpath->query("//iframe/@src")->item(0)->textContent;
preg_match('/.*&ll=([\d.,]+)&.*/', $string, $matches);
list($lat, $lng) = explode(',', $matches[1]);
$data['lat'] = $lat;
$data['lng'] = $lng;
精彩评论