#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    76
    Rep Power
    11

    Replacing multiple slashes with single slashes in urls/paths


    Hello all,

    I'm trying to clean up some URL's that I have in my database and I am trying to work out a way to use one of PHP's regex functions to strip out any double (or more) slashes in paths and urls.

    I'm generally quite good with regex but I'm having difficulty searching for a '/' as it seems to keep throwing an error with that character.

    Thanks as always!

    Matt.
    Regards, Matt Lowden
    http://www.mattlowden.com
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,905
    Rep Power
    6351
    It shouldn't throw an error unless you're using it as your delimiter:
    PHP Code:
    $new preg_replace("#/+#""/"$old); 
    -Dan

    Comments on this post

    • BlazerRotare agrees : For a swift response to a regex query!
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    76
    Rep Power
    11
    Originally Posted by ManiacDan
    It shouldn't throw an error unless you're using it as your delimiter:
    PHP Code:
    $new preg_replace("#/+#""/"$old); 
    -Dan
    I had a feeling it may have had something to do with using '/' as a delimiter. I should probably put some time asside to read up on the fundamentals of regex!

    Your sample code works perfectly, thankyou very much!

    Matt.
    Regards, Matt Lowden
    http://www.mattlowden.com

IMN logo majestic logo threadwatch logo seochat tools logo