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);
}
精彩评论