Home  |  Linux  | Mysql  | PHP  | XML
From:Andy Theuninck Date:Thu Mar 11 20:34:31 2010
Subject:DOMElement: td vs. th
I'm trying to parse a string containing an HTML table using the
builtin DOM classes and running into an odd problem.

Here's what I'm doing:
$dom = new DOMDocument();
$dom->loadHTML($str);
$tables = $dom->getElementsByTagName("table");
$rows = $tables->item(0)->getElementsByTagName('tr');
foreach($rows as $row){
foreach($row->childNodes as $node)
// stuff
}

This gives me the row elements in order and access to their contents.
The weird part is $node always appears to be a td tag - even when it's
a th tag in the original string (DOMElement::tagName is always "td"
(as well as DOMNode::nodeName and DOMNode::localName)). The th tags
definitely aren't being omitted; I still get nodes with their
contents, just with the wrong tag name.

Is there any way to override this behavior so that I can distinguish
between td tags and th tags?
Navigate in group php.general at sever news.php.net
Previous Next


Your recent visits
$_GET is Mangling Base64 value
Re: [PHP] $_GET is Mangling Base64 value
Re: [PHP] $_GET is Mangling Base64 value
Re: [PHP] Spreadsheet_Excel_Reader problem
Re: [PHP] Re: PHP in HTML code



  
© No Copyright
You are free to use Anything, but please consult your advocate before doing so as this website
also list content from other sources which may be copyrighted.
Site Maintained by Zareef Ahmed
Powered By PHP Consultants