This screenshot shows that the URL is getting stored in $url
This screenshots shows that after I add echo $html to the code, it says undefined variable $url and file_get_contents(): filename cannot be empty
Also, I have tried almost everything that's there on stackoverflow including file_get_html() and cURL. Nothing seems to work. Please tell me where I'm going wrong here.
<?php
include_once('simple_html_dom.php');
$base_url = "https://www.instagram.com/";
$html = "";
if ( isset($_POST['username']) ) {
$url = $base_url.htmlspecialchars($_POST['username'])."/";//concatenate $base_url to username to generate full URL
}
$html = file_get_contents($url); //access the URL in $url
$doc = new DOMDocument;
$doc->loadHTML($html); //get HTML of the webpage given by file_get_contents
$tags = $doc->getElementsByTagName('img');
$arr = (array)$tags;
if (empty($arr)) {
echo 'emptyarray';
}
foreach ($tags as $tag) {
echo $tag->getAttribute('src');
}
?>
Edit:
If 'http:// stackoverflow.com/questions' is used instead of 'https:// www.instagram.com/ its_kushal_here' file_get_contents() is working fine and not failing.