explode on whitespace

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

    explode on whitespace

    I'm assuming this is an easy question and I'm just missing something.
    I need to be able to explode a string on whitespace. The issue here is
    that I want to explode it such that all contiguous whitespace is one
    explode point. For example the following strings would all produce
    the same array of "words":

    This is a test.
    This is a test.
    This\tis a test.
    This\t \tis a test.

    Thoughts?

  • Oli Filth

    #2
    Re: explode on whitespace

    liam193 said the following on 01/07/2005 14:00:[color=blue]
    > I'm assuming this is an easy question and I'm just missing something.
    > I need to be able to explode a string on whitespace. The issue here is
    > that I want to explode it such that all contiguous whitespace is one
    > explode point. For example the following strings would all produce
    > the same array of "words":
    >
    > This is a test.
    > This is a test.
    > This\tis a test.
    > This\t \tis a test.
    >
    > Thoughts?
    >[/color]


    preg_split('/\d+/', $str);

    --
    Oli

    Comment

    • Chung Leong

      #3
      Re: explode on whitespace

      You mean preg_split('/\s+/', $str);

      \d is numeric characters.

      Comment

      • Oli Filth

        #4
        Re: explode on whitespace

        Chung Leong said the following on 01/07/2005 14:20:[color=blue]
        > You mean preg_split('/\s+/', $str);
        >
        > \d is numeric characters.
        >[/color]

        Yes indeed!

        --
        Oli

        Comment

        Working...