dummy help

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

Moderator: General Moderators

Post Reply
yshaf13
Forum Commoner
Posts: 72
Joined: Mon Apr 03, 2006 7:59 pm

dummy help

Post by yshaf13 »

This is probably a no brainer for you guys but i just can't wrap my head around the whole regex thing... I'm parsing an html document and i need to extract content between two tags so if i have in the page <b class="CPprodDescDet">lorem ipsum</b> it should just return "lorem ipsum".
this is what i have so far, but it's returning the whole thing (<b class...):
/^<b class="CPprodDescDet"> .*? <\/b>$/

what am i doing wrong?

is there a better way to do it?
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: dummy help

Post by Syntac »

Try this:

Code: Select all

$text = preg_replace("#<b class=\"CPprodDescDet\">(.*?)</b>#is", "$1", $the_string);
yshaf13
Forum Commoner
Posts: 72
Joined: Mon Apr 03, 2006 7:59 pm

Re: dummy help

Post by yshaf13 »

that works great, thanks alot.
Post Reply