如何在“:”之后获取网址

时间:2015-04-27 01:20:53

标签: php

我之前搜索过&找不到答案 http://i.stack.imgur.com/6mZRz.png

我希望在“:”

之后获取图片的网址

我使用简单的dom html

我的列表是..

include 'simple_html_dom.php';
$target = 'http://search.aol.com/aol/image?q=aku+ganteng';
$html = file_get_html($target);

foreach($html->find("div[class=inner]") as $f){ 
$crot = $f->find("img",0)->src; 

echo '<a href="'.$crot.'"><img src="'.$crot.'"/></a><br/>';
}

HTML列表

<div class="inner">
    <span class="imgc"></span>
    <a href="imageDetails?s_it=imageDetails&amp;q=aku+ganteng&amp;img=http%3A%2F%2Fsd.keepcalm-o-matic.co.uk%2Fi%2Fjarene-ibuk-ku-aku-ganteng-cok-d.png&amp;v_t=topsearchbox.image&amp;host=http%3A%2F%2Fwww.keepcalm-o-matic.co.uk%2Fp%2Fjarene-ibuk-ku-aku-ganteng-cok-d%2F&amp;width=129&amp;height=151&amp;thumbUrl=https%3A%2F%2Fencrypted-tbn1.gstatic.com%2Fimages%3Fq%3Dtbn%3AANd9GcQD_uhCuZ6yy19yB452fbEQAabTwa3xrOyVdArDf2COKl3AKKYX30dxAht7Nw%3Asd.keepcalm-o-matic.co.uk%2Fi%2Fjarene-ibuk-ku-aku-ganteng-cok-d.png&amp;b=image%3Fs_it%3DimageResultsBack%26v_t%3Dtopsearchbox.image%26q%3Daku%2Bganteng%26oreq%3D310738f642cd4b029e1f8c897168a385&amp;imgHeight=700&amp;imgWidth=600&amp;imgTitle=JARENE+IBUK%26%2339%3BKU+AKU+GANTENG+COK&amp;imgSize=39960&amp;hostName=www.keepcalm-o-matic.co.uk" onclick="return sl.sl(null,null,null,this,'image_results',1)">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQD_uhCuZ6yy19yB452fbEQAabTwa3xrOyVdArDf2COKl3AKKYX30dxAht7Nw:sd.keepcalm-o-matic.co.uk/i/jarene-ibuk-ku-aku-ganteng-cok-d.png" width="129" height="151" alt="JARENE IBUK'KU AKU GANTENG COK" title="JARENE IBUK'KU AKU GANTENG COK"></a>
  </div>

我希望得到这个

的一部分

sd.keepcalm-o-matic.co.uk/i/jarene-ibuk-ku-aku-ganteng-cok-d.png

如何获得完整的网址目标?

1 个答案:

答案 0 :(得分:0)

你可能需要这个:

$crot= "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQD_uhCuZ6yy19yB452fbEQAabTwa3xrOyVdArDf2COKl3AKKYX30dxAht7Nw:sd.keepcalm-o-matic.co.uk/i/jarene-ibuk-ku-aku-ganteng-cok-d.png"

preg_match_all('/.*:(.*?)$/sim', $crot, $part, PREG_PATTERN_ORDER);
$part = $part[1][0];
echo $part;

输出:

sd.keepcalm-o-matic.co.uk/i/jarene-ibuk-ku-aku-ganteng-cok-d.png

完整代码:

<?

include 'simple_html_dom.php';
$target = 'http://search.aol.com/aol/image?q=aku+ganteng';
$html = file_get_html($target);

foreach($html->find("div[class=inner]") as $f){ 
$crot = $f->find("img",0)->src; 
$ahh = str_replace("thumbs","download",$crot);
$wall = str_replace("t1","1920x1080",$ahh); 

preg_match_all('/.*:(.*?)$/sim', $crot, $part, PREG_PATTERN_ORDER);
$part = $part[1][0];
echo $part; //this is what you want.

echo "<a href='$crot'><img src='$crot'/></a><br/>";
}

?>