The following code is used on a php page and works well. My only problem is when the url is submitted and the artist parameter isnt clean it dosent return information, instead it returns this:
<lfm status="failed"><error code="6">
The artist you supplied could not be found
</error></lfm>
When it returns this I would like it to not continue the process. So i need some sort of if statement to check the response but I cant seem to code it properly. Thanks.
<table valign="top" width="90%" style="background-color:#fff; padding:0px 15px; border:1px solid ``#eae7e7;"><tr><th align="center" width="100%"><strong>Similar Artists</strong></th></tr><tr></tr>
<?php
$url = "http://ift.tt/1nZjbT3";
if (!file_exists($url)) {
$xml=simplexml_load_file("$url");
if ($url === false) {
// error!
}else{
foreach($xml->similarartists->artist as $artist){
foreach($artist->name as $name) {
$image = $artist->image;
$link = str_replace(' ', '-', $name);
echo "<tr><th width='60%'><a href='http://ift.tt/1sLisww'>$name</a></th><th width='40%'><img src='$image' alt='$name' height='50' width='50'> </th></tr><tr><th> </th></tr>";
}
}
}
}else{
}
?>
</table>
No comments:
Post a Comment