相关疑难解决方法(0)

如何通过PHP检查URL是否存在?

如何在PHP中检查URL是否存在(而不是404)?

php url

176
推荐指数
9
解决办法
28万
查看次数

12
推荐指数
1
解决办法
1万
查看次数

PHP:get_headers设置临时stream_context

我猜PHP的get_headers不允许上下文,因此我必须更改默认流上下文以仅获取请求的HEAD.这会导致页面上的其他请求出现一些问题.我似乎无法弄清楚如何重置默认流上下文.我正在尝试这样的事情:

$default = stream_context_get_default(); //Get default stream context so we can reset it
stream_context_set_default( //Only fetch the HEAD
      array(
    'http' => array(
       'method' => 'HEAD'
     )
  )
);
$headers = get_headers($url, 1); //Url can be whatever you want it to be
//var_dump($headers);
var_dump($default);
stream_context_set_default($default); //This doesn't work as it expects an array and not a resource pointer
Run Code Online (Sandbox Code Playgroud)

有谁知道解决这个问题?

我知道有人建议使用Curl,但我不愿意这个.谢谢!

php header stream head http-headers

7
推荐指数
2
解决办法
4217
查看次数

使用get_meta_tags()和get_headers()进行异常处理?

在PHP中,我使用的get_meta_tags()get_headers(),但是,当有一个404,这两个函数抛出一个警告.有什么办法让我抓住它吗?谢谢!

php exception-handling get-headers

3
推荐指数
1
解决办法
1677
查看次数

php get_headers位置

如何使用php get_headers只获取位置部分?

var_dump(get_headers('http://www.google.com',1));
Run Code Online (Sandbox Code Playgroud)

这个回报:

array(12) { [0]=> string(18) "HTTP/1.0 302 Found" ["Location"]=> string(21) "http://www.google.it/" ... }
Run Code Online (Sandbox Code Playgroud)

然后我用

echo (get_headers('http://www.google.com',1)["Location"];
Run Code Online (Sandbox Code Playgroud)

错误:Parse error: syntax error, unexpected '['在这一echo

php get-headers

3
推荐指数
1
解决办法
7447
查看次数