如何去掉http";/在php中?

如何去掉http";/在php中?,php,Php,假设一个名为$url的变量,其值可能是$url=http://www.example.com或$url=http://example.com或$url=www.example.com 现在,我想在www.example.com样式中回显$url,如何实现这一点?多谢各位 $url="http://www.example.com"; $data = parse_url($url); echo $data["host"]; PHP parse_url:您可以使用和来完成此工作。通过strpos搜索

假设一个名为$url的变量,其值可能是
$url=http://www.example.com
$url=http://example.com
$url=www.example.com

现在,我想在
www.example.com
样式中回显$url,如何实现这一点?多谢各位

$url="http://www.example.com";
$data = parse_url($url);
echo $data["host"];
PHP parse_url:

您可以使用和来完成此工作。通过strpos搜索url中的http(如果找到),替换为空白

if (strpos($url,'http://') !== false)
{
   $url=str_replace('http://','',$url);
}

使用
str\u replace
功能

echo str_replace('http://', '' , 'http://www.example.com');
$url =  str_replace('http://', '' , 'http://www.example.com');

如果(substr($data[“host”]、0,3)!='www'){echo“
www.“$data[“host”];}可以使用str_-ireplace以防万一,那么就用这个来补充它