note 84294 rejected from book.dom by nlopess
| From: | nlopess@php.net | Date: | Tue, 08 Jul 2008 12:03:57 +0000 |
| Subject: | note 84294 rejected from book.dom by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141265@lists.php.net to get a copy of this message | ||
Note Submitter: php at cremnet dot com
----
I have a problem with function. Function should search DOMNodList $res for a node with the
attributes. If it's not matches all of the attributes of the node it should be removed from the
DOMNodeList $res. How can do it?
///////////////////////////////
function findTag_all(DOMDocument &$doc,$tag_name,array $where=array()){
$res = $doc->getElementsByTagName($tag_name);
$c = count($where);
for($i=0;$res->item($i);$i++){
$f = 0;
foreach($where as $k=>$v){
$f = (ereg($v,$res->item($i)->getAttribute($k)))?++$f:$f;
}
if($f!=$c){
// i need this element to remove from the object $res
$res->item($i);
}
}
return $res;
}
$file = 'http://example.com/';
$doc = new DOMDocument('1.0');
$doc->loadHTMLFile($file);
$nods =findTag_all($doc,'div',array("id"=>"test"));
for($i=0;$tag->item($i);$i++){
var_dump($nods->item($i)->nodeValue);
}