Reputation: 5479
supposed a variable named $url,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.
Upvotes: 0
Views: 1016
Reputation: 86336
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);
}
Upvotes: 1
Reputation: 14318
use str_replace
function
echo str_replace('http://', '' , 'http://www.example.com');
$url = str_replace('http://', '' , 'http://www.example.com');
Upvotes: 3
Reputation: 26514
$url="http://www.example.com";
$data = parse_url($url);
echo $data["host"];
PHP parse_url: http://php.net/manual/en/function.parse-url.php
Upvotes: 5