0
我需要“计算”一个URL并重定向到它。我有以下代码:PHP:获取url后重定向
<?php
//Basic HTML parsing with PHP
include("simple_html_dom.php");
$htmlCode = file_get_html('http://example.net/example.html');
foreach($htmlCode->find('div[class=frontPageImage]') as $element) {
foreach($element->find('img') as $imagee)
$imgurl = $imagee->src;
}
header("'Location:".$imgurl."'");
?>
先在$ imgUrl的获得url后来重定向到URL ...但它不工作..
任何想法或建议?感谢
你能保证图像的SRC属性将始终包含完整的URL吗?如果他们使用相对路径,您可能会遇到问题。另外,您对多个图像有什么期望?重定向到第一个? – ernie 2012-07-23 22:18:11
要获得最后的图像,使用'$ imgurl = $ htmlCode-> find('div [class = frontPageImage] img') - > last_child() - > src;'。 – 2012-07-23 22:45:21