gpt4 book ai didi

php - 在 php 中获取请求的 url 的内容类型

转载 作者:可可西里 更新时间:2023-10-31 23:53:51 25 4
gpt4 key购买 nike

使用 php 我怎样才能将变量 $type 定义到 http://www.example.comcontent-type 中?

例如:$type定义为"text/html"

到目前为止,这是我正在使用的:

<?php
$url = 'http://www.example.com';
print_r(get_headers($url));
print_r(get_headers($url, 1));
?>

代码可以根据需要修改

最佳答案

你试过吗:

$type = get_headers($url, 1)["Content-Type"];

正如@Michael 在评论中指出的那样,如果没有最新版本的 PHP,此语法将无法工作。

你有没有试过:

$headers = get_headers($url, 1);
$type = $headers["Content-Type"];

?

关于php - 在 php 中获取请求的 url 的内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12023950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com