NYCPHP Meetup

NYPHP.org

[nycphp-talk] Regex for P Elements

Dan Cech dcech at phpwerx.net
Wed Jan 12 08:55:02 EST 2011


On 1/12/2011 8:24 AM, Randal Rust wrote:
> I am admittedly not very good with regular expressions. I am trying to
> pull all of the paragraphs out of an article, so that I can create
> inline links. Here is my script:
>
> $blockpattern='/<p*[^>]*>.*?<\/p>/';
> $blocks=preg_match_all($blockpattern, $txt, $blockmatches);
>
> This returns 0.

Shouldn't the expression be:

$blockpattern='/<p[^>]*>.*?<\/p>/';

I removed the * after the first p.

Dan




More information about the talk mailing list