Friday, 6 September 2013

PHP domdocument manipulation issues

PHP domdocument manipulation issues

I have a question regarding the domdocument.
My $html contains something like
texts …paragraph..
<table class='test'>
tr and td...
</table>
texts and more texts
I want to detect if there my html variable has a table element. If so,
wrap the other texts in <p> tag.
so it will be
<p>texts …paragraph..</p>
<table class='test'>
tr and td...
</table>
<p>texts and more texts</p>
My codes is like
$doc = new DOMDocument();
$doc->loadHTML($htmlString);
$tables = $doc->getElementsByTagName('table');
foreach ($tables as $table) {
//I am not sure what to do next...
}
Can someone help me out about this? Thanks so much!

No comments:

Post a Comment