Extract Total Number of Image And Missing Alt Attribute using php

Here i will show you how can you extract total number of images from HTML content and find out missing alt attribute of the image using very simple code using php.

$html = '
<html lang="en-US">
	<meta charset="UTF-8">
	<title>Extract Total Number of Image And Missing Alt Attributte</title>
	<img src="test.png">
	<img src="test.jpg" alt="Testing">
	<img src="test.gif">

$dom = new DOMDocument();
$images = $dom->getElementsByTagName("img");
$allImagesCount = 0;
$altEmptyTag = 0;
foreach ($images as $image)
	if (!$image->hasAttribute("alt"))
//echo $dom->saveHTML();
echo 'Total number of mages: '.$allImagesCount.'<br>';
echo 'Total number of mages missing alt attributes: '.$altEmptyTag.'<br>';
Tags: How To Retrieve An Image Attachment’s Alt Text, How to get image title/alt attribute, How to extract img src, title and alt from html using php, HTML DOM images Collection, php get all images from url, php extract images from html, php html parser, simple html dom get attribute value, php script to download all images from url, simple_html_dom.php download, php image scraper , php preg_match get img src, wordpress get image alt text, the images on this page contain alt attributes, get image title attribute using php

Leave a Reply

Related Posts: You may like

How to extract Heading tags using PHP from string

How to remove whitespace from string using php

Remove All Special Characters From String PHP

Redirecting HTTP to HTTPS with PHP

PHPKIDA Offering Free Tools:


Download Instagram Videos & Photos.

Download Now


Real Time Currency Converter

Convert Now


Robots.txt File Creater

Create Now


Compress yout HTML Code

Minify Now


Compress yout CSS Code

Minify Now


Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.