I use simple_html_dom
to get site's images. But sometimes, the image's link are not prefixed with the full domain URI, e.g. with http://example.com
. They appear as something like
- images/_home-ss-21.jpg
- /_home-ss-22b.jpg
- ./_1249a7s.png or
- ../../../a19489s_20110412.jpeg.
How to can I convert these URIs to absolute URIs including the protocol and domain information.
<?php
header('Content-type:text/html; charset=utf-8');
require_once 'simple_html_dom.php';
$v = 'http://www.typepad.com/';
$html = file_get_html($v);
foreach($html->find('img') as $element) {
echo $element->src.'<hr />';
}
?>