$test = "12,22 43 76 93 5 pass blahblahblahblah blah blah";

How would I split this string so I get :
[0] = 12,22 43 76 93 5
[1] = pass
[2] = blahblahblahblah blah blah

The $test string changes. the number of characters before and after pass can change and can include letters or numbers.

'pass' isn't always at the same point in the string and could appear more than once. But I want to split at the first match.
ie :

$test = "148 35 3 pass foo bar foo bar pass 123 foo bar";
[0] = 148 35 3
[1] = pass
[2] = foo bar foo bar pass 123 foo bar

I had tried explode() but that matches all occurrences of 'pass' and removes it in the process..

Any ideas ?
Thanks 🙂

    [man]strpos[/man] and [man]substr[/man].

    (P.S. [man]explode[/man] doesn't split at all positions if you ask it not to).

      Thanks.

      Just so I get this right in my head 😉

      $pos = strpos($test, 'pass');

      will find the first occurrence of pass in $test and return it's position.

      Then substr could be used for find any thing before that and after it ?
      How do I use substr to do this ?

      Thanks 🙂

        You say nothing in your original post about wanting to "find" anything before or after the word 'pass', just split the string at that position - strpos gives you the position at which you want to separate the string into pieces, and substr gives you a piece of the string.

          Thanks again for your reply.

          'find' was a bad choice of word !!

          This seems to give what I want.. is this right ?

          <?php
          $test = "12,22 43 76 93 5 pass blahblahblahblah blah blah";
          
          $pos = strpos($test, 'pass'); 
          
          $part1 = substr($test, 0, $pos);
          echo "Part1 = ". $part1 ."<br/>";
          
          $part2 = substr($test, $pos+4);
          echo "Part2 = ". $part2 ."<br/>";
          ?>
          

            Weedpacket made a mention of a feature of explode that you might have missed, i.e., it would be easier to write:

            <?php
            $test = "12,22 43 76 93 5 pass blahblahblahblah blah blah";
            
            list($part1, $part2) = explode('pass', $test, 2);
              Write a Reply...