Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:如何使用cURL获取网页的基本URL_Php_Curl - Fatal编程技术网

PHP:如何使用cURL获取网页的基本URL

PHP:如何使用cURL获取网页的基本URL,php,curl,Php,Curl,我正在尝试远程获取某人网页的内容。URL类似于: http://www.somewebsite.com/post/slug-of-the-post/ 我想通过PHP获取并显示/输出cURL是http://www.somewebsite.com/ 要使用的代码应该是什么样的 $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $url_parts = parse_url($url); echo $url_parts['scheme'].'://.'.

我正在尝试远程获取某人网页的内容。URL类似于:

http://www.somewebsite.com/post/slug-of-the-post/

我想通过PHP获取并显示/输出
cURL
http://www.somewebsite.com/

要使用的代码应该是什么样的

$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$url_parts = parse_url($url);
echo $url_parts['scheme'].'://.'.$url_parts['host'];

这将返回当前cURL会话中的URL,解析URL,然后显示方案和主机

如果你在你的问题上投入一些精力,那就太好了,例如,你试过什么,怎么会没有达到预期效果?