image - PHP preg_match_all can't get img src -
this question has answer here:
- get img src php 7 answers
i writing bot php. want images source using curl. can img tags can't src value img. empty string. can see error?
index.php
$baglan = baglan("http://www.hurriyetemlak.com/konut-satilik/sakarya-karasu-yali-emlakcidan-apartman-dairesi/detay/23585876"); preg_match('#<div id="dvsmallphoto" class="small-photo mt10"> <ul class="thumbs">(.*?) </ul> </div>#', $baglan, $resimlergenel); preg_match_all('#<li><figure>(.*?)</figure></li>#', $resimlergenel[1], $resimler); $yeni = str_replace('"', '\'', $resimlergenel[1]); preg_match_all("#<li><figure><img src='(.*?)' href='javascript:void(0);' onclick='return replaceimg(this)' tabindex='(.*?)' class='pretty' width='114' height='88' alt='(.*?)' /></figure></li> #", $yeni, $resimlinkler); print_r($resimlinkler); baglan.php
function baglan($url){ $curl = curl_init(); curl_setopt($curl, curlopt_url, $url); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_user_agent, $_server["http_user_agent"]); $cikti = curl_exec($curl); curl_close($curl); return str_replace(array("\n","\t","\r"), null, $cikti); }
you can end fixing regex not right tool this.
instead should use dom parser:
https://secure.php.net/manual/en/class.domxpath.php
it make life easier
here example:
Comments
Post a Comment