0

Hello and sorry for my bad english.

I am trying to get all images links from an third party website, but I want to get only the links that's do not have the alt attributes. I want to output the links.

Now I have this code:

<?php

$content = file_get_contents('domain.com');

preg_match_all('/<img(.*?)>/is',$content,$page_images);
$total_images = count($page_images[1]);

preg_match_all('/<img(.*?)alt="(.*?)"(.*?)>/is',$content,$alt_images);
$total_alt = count($alt_images[2]);

$missing_alt = $total_images - $total_alt; 


echo $missing_alt.' alt attributes are empty or missing';

?>

This code is working and gives the count of total images that are missing the alt attribute.

Now I want to output also the links that are missing the alt="" attribute.

Tomasz Kowalczyk
  • 10,472
  • 6
  • 52
  • 68

1 Answers1

-1

HTML shouldn't be parsed with regex.

It's much better, safer and easier to do it with DOMDocument or SimpleHTMLParser.

Alex
  • 4,674
  • 5
  • 38
  • 59