[英]PHP: redirect after get url
I need "calculate" an URL and redirect to it. 我需要“计算” URL并重定向到它。 I have the following code:
我有以下代码:
<?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."'");
?>
First in $imgurl get the url and later redirect to that url... but it doesn't work.. 首先在$ imgurl中获取URL,然后重定向到该URL ...但是它不起作用。
any idea or suggestion? 有什么想法或建议吗? thanks
谢谢
header("'Location:".$imgurl."'");
Should probably be: 应该可能是:
header("Location: " . $imgurl);
I removed the single quote '
because your HTTP header would look like: 我删除了单引号
'
因为您的HTTP标头如下所示:
'Location: http://site.com/image.jpg'
which is invalid because of the single quotes. 由于单引号无效。
You are also looping and finding many image URL's but only redirecting to the last one. 您还正在循环查找许多图像URL,但是仅重定向到最后一个URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.