removing all white spaces from scrolling text box

Discussion in 'PHP' started by t7584, Nov 16, 2006.

  1. #1
    removing all white spaces from scrolling text box

    My guestbook doesn't work correctly when I copy text from text processor into scrolling text box because of special characters that text processor leave. How do I remove all white spaces from scrolling text box and place new ones in there places.
     
    t7584, Nov 16, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Not sure if I understood you right.
    
    
    $text = preg_replace('/[\s\r\n\t]/', ' ', $text);
    
    PHP:
     
    nico_swd, Nov 16, 2006 IP
  3. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You asked about removing all white space, but this will remove spaces between words: soyourstringwilllooklikethis

    You might want to try just \r\t. \n is a valid end line character for unix and \s is spaces.

    For a lesser experienced PHP programmer or hobbiest, you might find str_replace easier to use than preg_replace (which requires some knowledge of regular expressions):

    http://www.php.net/manual/en/function.str-replace.php

    $test = str_replace(array("\r", "\t"), '', $text);
    Code (markup):
     
    ajscottsr, Nov 16, 2006 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    ^^ Note that \r and \t between single quotes won't be recognized as may expected. Use double quotes instead.
     
    nico_swd, Nov 16, 2006 IP
    ajscottsr likes this.
  5. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #5
    doh...

    Thanks nico :) -rep your way
     
    ajscottsr, Nov 16, 2006 IP
    nico_swd likes this.