How to get the absolute image URIs with SimpleHTMLDom [duplicate]

筅森魡賤 提交于 2019-12-06 15:12:44

Inside your foreach you can try the following to build the URL to the images.

$img_src = $element->src;
if(!strstr($img_src, 'http://')) {
    $img_src = $v . $img_src;
}
echo $img_src . '<hr /';

There are some scripts out there that can do this work as well to convert relative URLs to absolute URLs:

I have never tried them, but they should help you to work past this.

3 options:

  1. The image on the other site starts with http:// > use direct link
  2. Image starts with / > use home url of other site + image
  3. Image doesn't start with / > use full url + path to director of the site you are checking and add the image

./ is current directory so if you are at http://example.com and you see an image with src attribute ./hoopy_frood.png it means the whole address is http://example.com/hoopy_frood.png

../ means one directory up, so for example at http://example.com/ice_cream/sundae.html if you see an image with src attribute ../images/hoopier_is_not_a_word.gif then the image hoopier_is_not_a_word.gif is in a directory called images which is inside the site root directory along with the directory called ice_cream.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!