So lets say i have this url:

$url = $_POST;

I would like to remove the http://, the www. and the last "/". The trick is that the $url can be witten like this: $url = 'http://site.com/' like this: $url = 'www.site.com/' or even like this: $url = 'site.com/'. And so on and so forth making different combination with http:// www. and the /.
I have no idea how to remove all 3 of them if they all exist or just 1 of the if the other 2 don't exist!? Can anyone please help me with this!?

Personally, I'd literally just check for each of these in turn and update the string appropriately.

e.g.

$url = $_POST['site'];

if(strtolower(substr($url,0,7))=="http://"){
$url = substr($url,7);
}

if(strtolower(substr($url,0,4))=="www."){
$url = substr($url,4);
}

if(strtolower(substr($url,-1,1))=="/"){
$url = substr($url,0,-1);
}

super it worked like a charm, thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.