How seek and split content, in tags

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Druide
Forum Newbie
Posts: 1
Joined: Mon Apr 05, 2010 12:35 pm

How seek and split content, in tags

Post 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>?
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: How seek and split content, in tags

Post 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.
Post Reply