Strip all whitespace characters except ' ' (space)

    Date: 09/21/07 (PHP Community)    Keywords: no keywords

    I need to remove the leading and trailing whitespace and line returns from the following variable:

    $section_description = "
       
    asdf test one two three

    ";
    The following removes -all- whitespace:
    $section_description    = preg_replace('/\s+/','',$section_description);

    echo $section_description;
    asdftestonetwothree

    This has no effect:
    $section_description    = preg_replace('/ \t\n\x0B\f\r+/','',$section_description);


    echo $section_description;
       
    asdf test one two three

     
    I read that \s is synonymous with \t\n\x0B\f\r.  But that doesn't appear to be the case, or I'm misunderstanding something..

    Any help?

    Source: http://community.livejournal.com/php/586664.html

« Inheritance and constants || How do I look up… »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home