explode doesn't seem to work

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

    explode doesn't seem to work

    Hi all,

    $ttt = array();
    $ttt = explode("-", "test-niet");
    echo "$ttt[0] | $ttt[1]<br>";

    Should give
    test | niet

    but gives

    test-niet |

    Which meens the string is cut into 2 pieces. Someone knows what i m doing
    wrong?

    Regards
    Stijn


  • Daniel Tryba

    #2
    Re: explode doesn't seem to work

    Stijn Goris <mepisto@hotmai l.com> wrote:[color=blue]
    > $ttt = array();
    > $ttt = explode("-", "test-niet");
    > echo "$ttt[0] | $ttt[1]<br>";
    >
    > Should give
    > test | niet
    >
    > but gives
    >
    > test-niet |[/color]

    Where can we admire this behavior?

    Running above code (after adding print_r):
    $ php4
    <?php
    $ttt = array();
    $ttt = explode("-", "test-niet");
    echo "$ttt[0] | $ttt[1]<br>";
    print_r($ttt);
    ?>
    test | niet<br>Array
    (
    [0] => test
    [1] => niet
    )
    $

    Proof it works perfectly like expected.

    --

    Daniel Tryba

    Comment

    • Stijn Goris

      #3
      Re: explode doesn't seem to work


      "Daniel Tryba" <news_comp.lang .php@canopus.nl > wrote in message
      news:ck8o8i$bre $1@news.tue.nl. ..[color=blue]
      > Stijn Goris <mepisto@hotmai l.com> wrote:[color=green]
      >> $ttt = array();
      >> $ttt = explode("-", "test-niet");
      >> echo "$ttt[0] | $ttt[1]<br>";
      >>
      >> Should give
      >> test | niet
      >>
      >> but gives
      >>
      >> test-niet |[/color]
      >
      > Where can we admire this behavior?
      >
      > Running above code (after adding print_r):
      > $ php4
      > <?php
      > $ttt = array();
      > $ttt = explode("-", "test-niet");
      > echo "$ttt[0] | $ttt[1]<br>";
      > print_r($ttt);
      > ?>
      > test | niet<br>Array
      > (
      > [0] => test
      > [1] => niet
      > )
      > $
      >
      > Proof it works perfectly like expected.
      >
      > --
      >
      > Daniel Tryba
      >[/color]

      Is seems to work now. Probably has to do with a caching problem. I m working
      on a remove server and the old code was maybe still in use.


      Comment

      • Andy Hassall

        #4
        Re: explode doesn't seem to work

        On Sat, 9 Oct 2004 15:06:36 +0200, "Stijn Goris" <mepisto@hotmai l.com> wrote:
        [color=blue]
        > $ttt = array();
        > $ttt = explode("-", "test-niet");
        > echo "$ttt[0] | $ttt[1]<br>";
        >
        >Should give
        >test | niet
        >
        >but gives
        >
        >test-niet |
        >
        >Which meens the string is cut into 2 pieces. Someone knows what i m doing
        >wrong?[/color]

        As Daniel Tryba points out, the code you posted gives the _expected_ output
        you posted, not the output you said it gives.

        So, it's either a particularly silly bug in your version of PHP (which are you
        using?) or we're not seeing the actual problem here.

        Here's a completely wild guess - the data where this actually happens has come
        from someone who's been using Microsoft Word, and instead of there being a '-'
        dash character, Word's replaced it with an em-dash, which is a different
        character.

        --
        Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
        <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

        Comment

        Working...