What on earth does this do?

Discussion in 'PHP' started by interwho, Dec 11, 2010.

  1. #1
    Hi everyone,

    Ok, so I just finished a script, and was just optimizing it, when I came across this line of code in one of the replacement passes:

    
    $str2 = preg_replace("/(\s){2,}/",'$1',$newcontent);
    
    PHP:
    I forgot to comment the code :( and now I don't know what this line replaces. If anyone can help me, it would be great! Thanks!
     
    interwho, Dec 11, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think it strips extra whitespaces, but I have not seen it done that way before.
     
    Cash Nebula, Dec 12, 2010 IP
  3. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #3
    i think it strips first 2 spaces.
     
    olddocks, Dec 12, 2010 IP
  4. cyberfox

    cyberfox Member

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    It removes 2+ spaces , I don't think it's complete though
     
    cyberfox, Dec 12, 2010 IP
  5. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #5
    Thanks for your help! +1 rep to all who helped!
     
    interwho, Dec 12, 2010 IP
  6. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #6
    $str2 = str_replace("  ","",$from_content);
    PHP:
    $str2 will replace 2 empty spaces, with nothing $from_content
     
    MyVodaFone, Dec 12, 2010 IP