On Wed, Jan 12, 2011 at 9:30 AM, Jim Yi <j...@jimyi.com> wrote:
> 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
>

As Rob Marscher pointed out, using the DOM support can be tricky. What
you get out is not always what you put in, even if what you put in was
technically well-formed. Dreamweaver-y code (empty <font></font>
garbage) is a nightmare.

It's also slower than regex (which is slower than strpos()). So yeah,
it's super convenient and clean, but there are big trade-offs to using
it in some cases.
_______________________________________________
New York PHP Users Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/Show-Participation

Reply via email to