Re: DOMDocument help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?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@xxxxxxx> wrote in message 
news:4993F090.9090804@xxxxxxxxxx
> 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? 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux