preg_split problem | | Peter wrote:
> L.S.
>
> I am trying to cut a string into substrings. The string at hand looks
> something like this:
>
> $data='one|two|three|four\nfive|six|seven|eight'; //observe the chr(10) in
> the middle
>
> I would like to have this split two times. Once to give me the two
> 'sentences' 'one|two|three|four' and 'five|six|seven|eight'. Then, each of
> these sentences would be split into their repective words. Initially I
> thought it would be simple:
>
> $sentence=preg_split("\n",$data); //should give me an array $sentence
> $word=preg_split("|",$sentence[0]); //should give me an array $word
>
As pointed out elsewhere, it is better to use explode.
However, if you are doing things like this with pcre, you have to bear in mind
that if your expressions contain newlines, you have to use a multiline modifier.
Have a read and a play with it (read the manual stuff on modifiers)
Matt |