开发者

how to strip out the http"// in php?

supposed a variable named $ur开发者_开发知识库l,whcih value maybe $url=http://www.example.com or $url=http://example.com or $url=www.example.com

now, i want to echo the $url in www.example.com style, how to does this? thank you.


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

PHP parse_url: http://php.net/manual/en/function.parse-url.php


use str_replace function

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


You can use strpos and str_replace to do the job. Search the http in the url through strpos if found replace with blank.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜