How to Extract img src and alt value From HTML using PHP?

Hello Guys i will tell you today through Experts PHP Tutorial, How You Can Extract the src value or alt value of the img tag of any HTML Page of PHP. i will tell you step by step. So let’s go.

First of all you create a php file. You can name that file according to yourself. Add the code below to your php file and run it on your local server and you will get your output.

extractimg.html

<?php 
function page($url) { 
$dom = new DOMDocument('1.0'); 
@$dom->loadHTMLFile($url); 
$imgget = $dom -> getElementsByTagName('img');
foreach ($imgget as $element) {
$src = $element -> getAttribute('src');
$alt = $element -> getAttribute('alt'); 
$height = $element -> getAttribute('height');
$width = $element -> getAttribute('width');
echo '<img src="'.$src.'" alt="'.$alt.'" height="'
. $height.'" width="'.$width.'"/>'; 
} 
} 
page("https://www.liveleak.com/view?t=C4NfS_1568028067"); 
?>

 

DOMDocument :- The PHP Document Object Model (DOM) represents your entire document through a single object. This object is a document.With the help of this object, you can access any HTML element in the entire document. DOM provides you control of all HTML elements (tags) of a web page. With its help, you can remove any element or add new elements.

Cialis (Tadalafil) är den främsta konkurrenten till Viagra (Sildenafil) på marknaden för erektil dysfunktion. köpa Cialis i Sverige föredras av många på grund av sin längre varaktighet och anses vara det mest kostnadseffektiva varumärkesbaserade ED-läkemedlet som finns tillgängligt i Sverige. Cialis finns i två varianter: Cialis och Cialis Daily, och fyra olika doseringar: 2,5 mg, 5 mg, 10 mg och 20 mg, erbjuder Cialis också en rad olika alternativ för att passa patientens behov.