View Full Version : trim() a phrase instead of individual characters

03-20-2007, 04:10 PM

I have a script that takes a URL and trims characters from it for storage in a database. My intention is to trim http:// from the start of the URL and and trailing slashes. For this I have been using the following:

$url = trim($url, "http://");

Unfortunately a problem has arisen in that any url's ending in .net have "t" trimmed from the end because, I realise, trim() strips out individual characters, not phrases.

Is there any way trim() can be modified to only find and remove the instance of http:// in it's entirety, and ignore single instances of the letters, or is there an alternative function I should be looking at?

03-20-2007, 04:13 PM
$url = str_replace("http://","",$url);

03-20-2007, 05:04 PM
:thumbsup: Thanks

I'd used str_replace on the previous line believe it or not... sometimes you just need a second pair of eyeballs eh?