I have a string and want to remove http://www.domain.com part of it. $url= http://www.domain.com/newsite.php?id=12 I want to extract the newsite.php?id=12 bit.
PHP has a lovely builtin function called parse_url(), so in your case you could use: $urlparts = parse_url("http://www.domain.com/newsite.php?id=12"); $extracted = $urlparts['path'].'?'.$urlparts['query']; print $extracted; PHP: You can also use explode() and remove the first two/three parts of the array.
How would I use the explode function to remove the domain name part as I may have additional / and & in the url
<?php $url = "http://www.lol.com/test/sweet/?value=lala&thanmorevalue=loool"; $parts = explode("/",$url); array_shift($parts);array_shift($parts);array_shift($parts); $newurl = implode("/",$parts); print $newurl; // test/sweet/?value=lala&thanmorevalue=loool ?> PHP: Ugly code, but since the amount of array_shift()'s is static, I'm not bothering with a for() loop