I have been trying to modify HTML tag elements, I have a huge list of HTML files which needs to be modified.
I need the lines between the images and the following text removed. I am using PHP. I am using a DOMDocument to access all the nodes and I am also able to get the nodepath. But I am unable to get to modify that particular HTML tag from the nodepath. Is this possible?
This is what I have as of now:
$dom = new DOMDocument();
$dom->loadHTMLFile($pathname);
$i=0;
$allNodes = $dom->getElementsByTagName('*');
$tagNamesArray = array();
foreach($allNodes as $node) {
$tagNodePath = $node->getNodePath();
$tagName = end(explode('/',$node->getNodePath()));
$tagNamesArray[$i][1] = $tagName;
$tagNamesArray[$i][2] = $tagNodePath;
$i++;
}
checkForLines($tagNamesArray, $dom);
function checkForLines($tagsArray, $dom) {
$xPath = new DOMXpath($dom);
for($i=0 ; $i<(count($tagsArray)-1) ; $i++) {
if($tagsArray[$i][1] == 'img' && $tagsArray[$i+1][1] == 'br') {
echo $tagsArray[$i+1][2].'<br>';
$lineTag = $xPath->query($tagsArray[$i+1][2]);
$domElement = $dom->removeChild($lineTag);
}
}
}
qp($html)->find("div a")->wrap("<p class=new>");for example.$dom->saveHTMLFile($filename)?