enjoylife
enjoylife

Reputation: 5479

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

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

Answers (3)

Shakti Singh
Shakti Singh

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

S L
S L

Reputation: 14318

use str_replace function

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

Upvotes: 3

amosrivera
amosrivera

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

Related Questions