Re: DOMDocument help
| From: | RottenEye | Date: | Thu, 12 Feb 2009 15:52:43 +0000 |
| Subject: | Re: DOMDocument help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288171@lists.php.net to get a copy of this message | ||
<?php
$string = 'this <b>is</b> a string <b>that</b> has some bold
<b>words</b>';
$doc = new DOMDocument;
$doc->loadHTML($string);
$items = $doc->getElementsByTagName('b');
for( $i = 0; $i < $items->length; $i++ ){
echo $items->item($i)->nodeValue . "<br />\n";
}
?>
""Michael A. Peters"" <mpeters@mac.com> wrote in message
news:4993F090.9090804@mac.com...
> I'm using php 5.2.5 with the php-xml module.
>
> I need to split a string of html into elements.
>
> IE -
>
> this <b>is</b> a string <b>that</b> has some bold
> <b>words</b> in it.
>
> I need to be able to take that string and split it up into textNodes for
> the parts that are not in bold text, and bold nodes containing the bold
> elements.
>
> I've tried creating a new DOMDocument object and inputing the line into
> it -
>
> $tmpNode = new DOMDocument;
> $tmpNode->loadHTML($string);
>
> but I can't figure out how to get the the useful nodes out of it to then
> append as children in the document I'm creating.
>
> Any tips on how to do this?