You probably want to check if $videoid
is defined at the beginning of the script. The ampersand in @file_get_html
below will suppress error messages in the case when the page is not found.
<?php
include('include/simple_html_dom.php');
$website = 'http://vine.co/v/';
#$videoid = 'haiKqBFA9Yw';
$videoid = array_key_exists("videoid", $_GET)? $_GET["videoid"]: "";
if ($videoid != "") {
$page = $website . $videoid;
$html = @file_get_html($page);
if ($html) {
foreach ($html->find('meta[property=og:image]') as $element) {
$image = $element->content;
//Change http to https and remove versionId=
$image = str_replace( 'https://', 'http://', $image );
$image = str_replace( 'versionId=', '', $image );
//Remove extra version id junk
$image = substr($image, 0, strpos($image, "?"));
$images[] = $image;
}
echo "<pre>" . print_r($images, TRUE) . "</pre>";
} else {
echo "Page not found: $page";
}
} else {
echo "It appears videoid is empty.";
}
?>