How to use DomDocument to remove or replace the "broken" link?

Tell me how to remove or replace the "broken" link via the DomDocument

to was like this:
<a href=""></a>
the <a href></a>
the <a href>asdasd</a>
<a href target="_blank">asdasd</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){

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)
June 8th 19 at 16:39
3 answers
June 8th 19 at 16:41
if(strpos($mystring, 'href=""') !== false || strpos($mystring, '>') !== false){
 echo 'the string is a null reference or an empty url';
nah, text (markup) can be tens of pages - al commented on June 8th 19 at 16:44
June 8th 19 at 16:43

all = document.querySelectorAll('a[href=""]');
all.forEach(function(el) {
probably better than using DomDocument - al commented on June 8th 19 at 16:46
June 8th 19 at 16:45
It's simple:
  1. Pre-get all href-string of HTML markup:
  2. Find all matches ("broken" links) and replace using preg_replace:

Thank you) but with the regular season I got excited( Better with DomDocument. The only question is how.. besides <a target>link</a> passes by... - al commented on June 8th 19 at 16:48
well the regular season performance and faster CPU - significantly "cheaper."
In the regular season and not checking for non-existence of the href - and you need to edit (this is not a problem). - al commented on June 8th 19 at 16:51

Find more questions by tags PHP