Page 1 of 1

How seek and split content, in tags

Posted: Mon Apr 05, 2010 12:39 pm
by Druide
I've a question about how use the regular expression to find a tag.

For sample. I've a code:
<div class=Section1>

<p class=Title><o:p>&nbsp;</o:p></p>

<p class=Title align=center style='text-align:center'>title title title title </p>

<p class=Title><o:p>&nbsp;</o:p></p>

<p class=Author><st1:PersonName ProductID=""
w:st="on">Name</st1:PersonName></p>

<p class=Author>Some <st1:PersonName
ProductID="" w:st="on">thing</st1:PersonName>
about the author</p>

<p class=Author>More about the author</p>

<p class=Author><o:p>&nbsp;</o:p></p>

<p class=chapter>1. chapter 1</p>

<p class=Text>text...</p>
<p class=Text>text...</p>
Yes, it's with garbage from msword.

I need take in this code the follow:
Name
Some thing about the author
More about the author
I tried but I can't get the point.

If I use like this:
preg_match_all('#<p class=Author>([^<]*)</p>#s',$text,$val);
Don't work, 'cause there are more </p> in the text. How I do for it stop in the first </p>?

Re: How seek and split content, in tags

Posted: Mon Apr 05, 2010 2:09 pm
by tr0gd0rr
Try allowing all characters but being ungreedy: instead of `([^<]*)` use `(.*?)`.

You need to use the `s` modifier, but you already are. You'll also need to run striptags() on each match.