[nycphp-talk] Regex for P Elements
Randal Rust
randalrust at gmail.com
Wed Jan 12 09:39:29 EST 2011
On Wed, Jan 12, 2011 at 9:30 AM, Jim Yi <jim at 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
> }
I will have to try this out, because I am not sure that the approach I
was taking will work. This however, probably would because it will
only apply changes to the P elements in the text. The trouble I ran
into was that links were being applied to H1-H6 elements as well,
which isn't what I want.
--
Randal Rust
R.Squared Communications
www.r2communications.com
www.facebook.com/r2communications
614-370-0036
More information about the talk
mailing list