String parsing help

Posted by Click Upvote on Stack Overflow See other posts from Stack Overflow or by Click Upvote
Published on 2010-03-25T21:07:36Z Indexed on 2010/03/25 21:13 UTC
Read the original article Hit count: 485

Filed under:
|
|

I have a string like the following:

$string = "
<paragraph>apples are red...</paragraph>
<paragraph>john is a boy..</paragraph>
<paragraph>this is dummy text......</paragraph>
";

I would like to split this string into an array contanining the text found between the <paragraph></paragraph> tags. E.g something like this:

$string = "
<paragraph>apples are red...</paragraph>
<paragraph>john is a boy..</paragraph>
<paragraph>this is dummy text......</paragraph>
";

$paragraphs = splitParagraphs($string);
/* $paragraphs now contains:
   $paragraphs[0] = apples are red...
   $paragraphs[1] = john is a boy...
   $paragraphs[1] = this is dummy text...
*/

Any ideas?

P.S it should be case insensitive, <paragraph>, <PARAGRAPH>, <Paragraph> should all be treated the same way.

© Stack Overflow or respective owner

Related posts about regex

Related posts about php