Okay so basically this script will print an image with the stats retrieved from the XML file at http://75.126.211.99/player2xml.php?n=(playersname). Problem is, if the name is wrong the XML file will return just "Error". And that makes my script go crazy. Working example: http://stats.aruaguru.com/stats.php?q=xadet3 Non-working example: http://stats.aruaguru.com/stats.php?q=thisnamedoesntexist How can I make it so it doesn't do anything if the Character tag doesn't exist? if($_GET["q"] != NULL) { create_image(); exit(); } else { echo "Error."; } function create_image() { $q=$_GET["q"]; $xmlDoc = new DOMDocument(); $xmlDoc->load("http://75.126.211.99/player2xml.php?n=".$q.""); $x=$xmlDoc->getElementsByTagName('Character'); $font = 'PORKYS.TTF'; $image = imagecreatefrompng('pstats.png'); $colour = ImageColorAllocate($image, 229, 229, 229); $y=$x->item($i)->getElementsByTagName('Level'); $z=$x->item($i)->getElementsByTagName('Job'); $name = $q; $class = $z->item(0)->childNodes->item(0)->nodeValue; $level = $y->item(0)->childNodes->item(0)->nodeValue; imagettftext($image, 8, 0, 110, 33, $colour, $font, $name); imagettftext($image, 8, 0, 110, 53, $colour, $font, $class); imagettftext($image, 8, 0, 110, 72, $colour, $font, $level); header("Content-Type: image/png"); Imagepng($image); ImageDestroy($image); } PHP:
Try: if (@$xmlDoc->load("http://75.126.211.99/player2xml.php?n=".$q."")) { $class = $z->item(0)->childNodes->item(0)->nodeValue; $level = $y->item(0)->childNodes->item(0)->nodeValue; } else { $class = 'default'; $level = 'default'; } PHP: