Removing space characters from a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mr_burns

    Removing space characters from a string

    Hi there,

    How do I remove space characters from a string using PHP?

    For example, the following string...

    ' hi there, my name is burnsy '

    ....has spaces, at the edges and inbetween the other characters. I know
    I can use trim() to remove the outside ones but how do i remove the
    inbetween ones so it will read:

    'hithere,myname isburnsy'

    Any ideas? Cheers

    Burnsy
  • Michael Fesser

    #2
    Re: Removing space characters from a string

    .oO(mr_burns)
    [color=blue]
    >How do I remove space characters from a string using PHP?[/color]

    str_replace()

    Micha

    Comment

    • Bernhard Georg Enders

      #3
      Re: Removing space characters from a string

      <?php
      $YourString = ' hi there, my name is burnsy ';
      $YourNewString = explode(' ', $YourString);
      $YourString = implode("", $YourNewString) ;
      echo $YourString;
      ?>

      Hope this helps,

      Bernhard Enders.

      Comment

      • Alvaro G Vicario

        #4
        Re: Removing space characters from a string

        *** mr_burns wrote/escribió (26 Oct 2004 05:05:58 -0700):[color=blue]
        > How do I remove space characters from a string using PHP?[/color]

        This removes spaces, tabs, carriage returns...

        preg_replace('/[[:space:]]/', '', $foo);

        If you just want to get rid of actual space char:

        str_replace(' ', '', $foo);


        --
        -- Álvaro G. Vicario - Burgos, Spain
        -- Thank you for not e-mailing me your questions
        --

        Comment

        Working...