Answer the question
In order to leave comments, you need to log in
How to remove or replace a broken link using DomDocument?
Tell me how to remove or replace a "broken" link through DomDocument
so that there is something like this:
<a href="http://yandex.ru"></a>
<a href=""></a>
<a href="">asdasd</a>
<a href="" target="_blank">asdasd</a>
<a></a>
<a><p>......
foreach ($links as $link){
if($link->getAttribute('href') == false){
$link->parentNode->removeChild($link);
}
}
asdasd asdasdasdas dasd <a target="_blank">link</a> asdasdasdsadasda sdas dasd asdasd sad <a target="_blank">являются</a> sadsadsad
Answer the question
In order to leave comments, you need to log in
if(strpos($mystring, 'href=""') !== false || strpos($mystring, '></a>') !== false){
echo 'в строке есть пустая ссылка или пустой url';
}
https://regex101.com/r/UczLYE/2
all = document.querySelectorAll('a[href=""]');
all.forEach(function(el) {
el.remove();
});
It's simple:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question