[nycphp-talk] Regex for P Elements
Jim Yi
jim at jimyi.com
Wed Jan 12 09:30:44 EST 2011
This problem is much better suited for an XML parser, and it makes your code
more readable as well. Code snippet:
$dom = new DOMDocument();
$dom->loadHTML($txt);
$items = $dom->getElementsByTagName('p');
foreach ($items as $paragraph) {
echo $paragraph->nodeValue;
// You can also manipulate and update the nodeValue within this loop as
well
}
Jim Yi
On Wed, Jan 12, 2011 at 9:25 AM, Randal Rust <randalrust at gmail.com> wrote:
> On Wed, Jan 12, 2011 at 9:20 AM, Dan Cech <dcech at phpwerx.net> wrote:
>
> > Good call, I missed the multiple-line thing. In this situation though
> you'd
> > actually want /s like:
> >
> > $blockpattern='/<p[^>]*>.*?<\/p>/s';
>
> That's it. I tried it with /m, but it gave me 0 results. Replaced with
> /s and now I have the array of 33 paragraphs, as expected. Thanks for
> the help!
>
> --
> Randal Rust
> R.Squared Communications
> www.r2communications.com
> www.facebook.com/r2communications
> 614-370-0036
> _______________________________________________
> New York PHP Users Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/Show-Participation
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20110112/86aa0ab6/attachment.html>
More information about the talk
mailing list