If I had a string that looked something like:

<tag>
Blah blah blah
</tag>

<tag>
foo bar
</tag>

<tag>
moo cow
</tag>

What would be the best way to split it so I could get an array that would look like

$array[0] = "blah blah blah";
$array[1] = "foo bar";
$array[1] = "moo cow";

I can't think of a simple way to do this with PHP. Any suggestions?

Thanks

    preg_match('~<tag>(.*)</tag>~iUs', $string, $matches); 

      According to the docs on php.net it says that

      "$matches[1] will have the text that matched the first captured parenthesized subpattern, and so on. "

      Now I am trying this code you suggested and by going print_r($matches) after it only returns up to $matches[1]. It only gets the first instance it matches but does not find any of the other four.

        I figured it out, I used preg_match_all.

          Write a Reply...