In the previous tutorial we learn about the simple HTML Dom we have successfully installed the term PHP file in our server now we want to extract data from any website is we want to extract any image or links then we should follow the following code

<!DOCTYPE html>
<html lang="en-US" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="UTF-8">
</head>
<body>
<?php
include "simple_html_dom.php";
$url = "http://www.fabulouspost.com/2017/06/Daily-Hot-Bollywood-Actress.html";
$html = file_get_html($url);
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';
?>
</body>
</html>

If we want to extract the all links from the given URL then we just have to change “img” to “a” here “a” defines the tag name and as a element we have to use its attribute that’s href in this way we can extract any attribute value of any tag


<!DOCTYPE html>
<html lang="en-US" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="UTF-8">
</head>
<body>
<?php
include "simple_html_dom.php";
$url = "http://www.fabulouspost.com/2017/06/Daily-Hot-Bollywood-Actress.html";
$html = file_get_html($url);
// Find all links
foreach($html->find('a') as $element)
echo $element->href . '<br>';
?>
</body>
</html>
By using this code you can easily extract contents from a URL in the next tutorial we will discuss about that how can we simply extract plain text from a URL or a div or any other tags