Forum Moderators: coopster

Message Too Old, No Replies

Regex preg_match_all problem

Getting every instance

         

Sathallrin

4:22 pm on Dec 2, 2005 (gmt 0)

10+ Year Member



I have a section of a string such as this:
"jibberish hello jibberish here world jibberish hello jibberish ahere world jibberish hello more jibberish here world"

I want to each instance of the string where it has the hello world with some text inbetween.

I have tried using this:
preg_match_all('/hello.*world/s', $string, $arr);

But this matches the whole section of this:
"hello jibberish here world jibberish hello jibberish ahere world jibberish hello more jibberish here world"
in $arr[0][0]

I want it to be like this:

$arr[0][0] = "hello jibberish here world"
$arr[0][1] = "hello jibberish ahere world"
$arr[0][2] = "hello jibberish more here world"

Thank you.
Sathallrin

Sathallrin

4:39 pm on Dec 2, 2005 (gmt 0)

10+ Year Member



Nevermind.. I figured this out. I needed the U flag
It worked like this:
preg_match_all('/hello.*world/Us', $string, $arr);