我想知道是否可以提供图像的超链接,例如:如果给出图像URL:我有一个网页说(http://www.example.com),图像例如:
<a href="http://example.com/12344/623/2"><img id="img" src="http://example.com/623/5602225.jpg" alt="The Image" name="img" height="1140" width="800"></a>
我在想有可能得到这个
http://example.com/12344/623/2
当我给
http://example.com/623/5602225.jpg
作为PHP和CURL的输入?
是的,您需要解析html。
当您标记SimpleHtmlDom时:
include "simple_html_dom.php";
//example html
$html = '<a href="http://example.com/12344/623/1"><img id="img" src="http://example.com/623/5602224.jpg" alt="The Image" name="img" height="1140" width="800"></a>';
$html .= '<a href="http://example.com/12344/623/2"><img id="img" src="http://example.com/623/5602225.jpg" alt="The Image" name="img" height="1140" width="800"></a>';
$html .= '<a href="http://example.com/12344/623/3"><img id="img" src="http://example.com/623/5602226.jpg" alt="The Image" name="img" height="1140" width="800"></a>';
//the image url to search for
$img = 'http://example.com/623/5602225.jpg';
//Note if you want to get the html from a url and not a string,
// use $som = file_get_html('http://www.example.com/');
$dom = str_get_html($html);
$url = $dom->find('img[src='.$img.']', 0)->parent->href;
//$url equals http://example.com/12344/623/2
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句