Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts

    trim() a phrase instead of individual characters

    Hello,

    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:

    PHP Code:
    $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?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    $url = str_replace("http://","",$url);

  • #3
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Thanks

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •