Sunday, March 31, 2019

dom - php DomDocument: how can i print an attribute of an element?



how do I print the an attribute of an element?



example:




$doc = new DOMDocument();
@$doc->loadHTML($page);
$xpath = new DOMXPath($doc);
$arts= $xpath->query("/td");

foreach ($arts as $art) {
here i wanna print the attribute class of the td element, how do i do so ?
}

Answer




use DOMElement::getAttribute



$art->getAttribute('class');


also, simpleHTMLDOM is more suitable for dealing with html:



$html = str_get_html($page);
foreach($html->find('td') as $element)
echo $element->class.'
';

}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...