<a href="http://yandex.ru"></a> the <a href></a> the <a href>asdasd</a> <a href target="_blank">asdasd</a> <a></a> <a></a>
......
In the DomDocument I'm looking for teshi without the href for example, and then try to delete this reference, but not everything you need is deleted because (I think due to the fact that the parent can be more than 1 child element and when deleting it only removes 1st)foreach ($links as $link){ if($link->getAttribute('href') == false){ $link->parentNode->removeChild($link); } }
dasd asdasd asdasdasdas
<a target="_blank">link</a> asdasdasdsadasda sdas dasd asdasd sad <a target="_blank">are</a> sadsadsad
removed only the 1st link, since they have 1N parent. If I again take a walk cycle, then is removed and the 2nd, but I don't know how many links can have 1 parent.. Tell me what to do pliz)
if(strpos($mystring, 'href=""') !== false || strpos($mystring, '>') !== false){
echo 'the string is a null reference or an empty url';
}
all = document.querySelectorAll('a[href=""]');
all.forEach(function(el) {
el.remove();
});
<a target>link</a> passes by...
commented on June 8th 19 at 16:48Find more questions by tags PHP