Zum Inhalt springen

Extending extension where I needs to use DOM

Erstellt am 7. November 2011 · Noch keine Antworten

Tags: Frage, English

xescjp ·

I am creating an extended extension and I need to parse the HTML. I need to use DOM inside the extension.
I have copied php_domxml.dll to ext directory of php extensions.
I have write extension=php_domxml.dll in php.ini.
I use the following code but doesn't work. The first line doesn't work because I have checked the value of $doc variable and its null.

$doc = new DOMDocument();

$doc->loadHTML($contingut);
/*** a new dom object ***/
$doc = new domDocument;

/*** discard white space ***/
$doc->preserveWhiteSpace = false;

/*** the table by its tag name ***/
$table = $doc->getElementById('directori');

/*** get all rows from the table ***/
$rows = $table->getElementsByTagName('tr');

/*** loop over the table rows ***/
foreach ($rows as $row)
{
/*** get each column by tag name ***/
$cols = $row->getElementsByTagName('td');
/*** echo the values ***/
$contingut.= $cols->item(0)->nodeValue.'<br />';
$contingut.=$cols->item(1)->nodeValue.'<br />';
$contingut.=$cols->item(2)->nodeValue;
$contingut.='<hr />';
}

Anybody could tell me how to use dom in a typo3 extension?

Thanks in advance

Francesc