Zend Framework Certification, MVC, Performance, Diagnosis and Maintainability, Mail, Infrastructure, Forms, Filtering and Validation, Coding Standards, Coding Standards, Coding Standards, Security, search, Web Services, Authentication and Access, Security, Database
Wednesday, 31 July 2013
Zend Dom Query Examples
$htmlData ='
<h3>
<img src="wow/img.jpg" /><a href="http://wow.com">wow link</a>
</h3>
<h3>
<img src="wow/img.jpg" ><a href="http://wow.com">wow link2</a>
</h3> ';
##########EXAMPLE1#############
$dom= new Zend_Dom_Query($htmlData);
$results = $dom->query('h3>a');
/*OUTPUT
Child Tag:
#text
wow link
http://wow.com$$$
Child Tag:
#text
wow link2
http://wow.com$$$ */
foreach($results as $result){
//echo $result->textContent;
$children = $result->childNodes;
if($children->length > 0){
foreach($children as $c){
echo "Child Tag: <br />";
echo $c->nodeName."<br />";
echo $c->nodeValue."<br />";
}
}
echo $result->getAttribute('href')."$$$<br /><hr />";
}
##########EXAMPLE1#############
##########EXAMPLE2#############
$dom= new Zend_Dom_Query($htmlData);
$results = $dom->query('h3');
/*OUTPUT
http://wow.com
http://wow.com
*/
foreach($results as $result){
echo $result->getElementsByTagName('a')->item(0)->getAttribute('href'); echo "<br>";
}
##########EXAMPLE2#############
Subscribe to:
Posts (Atom)