[英]PHP: redirect after get url
我需要“计算” 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 ...但是它不起作用。
有什么想法或建议吗? 谢谢
header("'Location:".$imgurl."'");
应该可能是:
header("Location: " . $imgurl);
我删除了单引号'
因为您的HTTP标头如下所示:
'Location: http://site.com/image.jpg'
由于单引号无效。
您还正在循环查找许多图像URL,但是仅重定向到最后一个URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.