SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    strip whitespace

    I am looking for a function that strips all white space from a string but looking at the manual i can find none.

    Should this be done using explode / implode ?

    Azaar

  2. #2
    SitePoint Addict richard_h's Avatar
    Join Date
    May 2002
    Location
    London
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Description
    string trim ( string str [, string charlist])


    Note: The optional charlist parameter was added in PHP 4.1.0

    This function returns a string with whitespace stripped from the beginning and end of str. Without the second parameter, trim() will strip these characters:

    http://www.php.net/manual/en/function.trim.php

    Not sure if that's what you're after?

  3. #3
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm looking to turn:

    12 London Road

    into

    12LondonRoad

    would

    PHP Code:
    $Identifier '12 London Road';
    echo 
    implode(''explode(' 'trim($Identifier))); 
    work ?

  4. #4
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To remove ALL whitspace you could do this:

    PHP Code:
    $str preg_replace("/[[:space:]]/"""$str); 
    I think thats the proper regex shorthand anyway.....
    THE INSTRUCTIONS BELOW ARE OLD AND MAY BE INACCURATE.
    THIS INSTALL METHOD IS NOT RECOMMENDED, IT MAY RUN
    OVER YOUR DOG. <-- MediaWiki installation guide

  5. #5
    SitePoint Addict richard_h's Avatar
    Join Date
    May 2002
    Location
    London
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:
    PHP Code:
    str_replace(" """"12 London Road"); 

  6. #6
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah nice one, thnx

  7. #7
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this doesnt seem to be stripping the whitespace at all

  8. #8
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    UK
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok - ignore me, i was stupid

  9. #9
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you assigning it to a variable or printing it?

    PHP Code:
    <?php

        $str 
    '12 London Road';

        echo 
    str_replace' '''$str );

    ?>
    - or -

    PHP Code:
    <?php

        $str 
    '12 London Road';

        
    $var str_replace' '''$str );

        echo 
    $var;

    ?>
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  10. #10
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Azaar
    ok - ignore me, i was stupid
    Ok!

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


Bookmarks

Posting Permissions

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