Reputation: 1
Good, I ask your help in the following problem, I have a document php with a code that removes the cover of songs that estam an xml document site last fm, the problem is that I have the correct code only when there is no cover the following message "Fatal error: Call to a member function xpath () on a non-object in /home/vhosts/radiojevn.6te.net/lastfm-3.php on line 23" I've tried modifying the code but without success .
If anyone able to help me I'm grateful!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-image: url(http://www.playtech.com.br/Imagens/produtos/indisponivel_vitrine.gif);
background-repeat: no-repeat;
background-size: 100%;
}
-->
</style>
</head>
<body marginheight="0" marginwidth="0">
<?php
$xml = simplexml_load_file('http://radiojoven.6te.net/NowOnAir.xml');
if ($xml === false)
{
echo("Url failed"); // do whatever you want to do
}
$artist = urlencode($xml->Event->Song->Artist['name']);
$url = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=$artist&api_key=50ac27433c63f7298064f434f4ef6d15");
$largeImage = $url->xpath('/lfm/artist/image[@size="mega"]')[0];
echo '<img src="'.$largeImage.'" ';
?>width="100%" height="100%" />
</html>
Upvotes: 0
Views: 3823
Reputation: 201
Your request is not valid xml file http://radiojoven.6te.net/NowOnAir.xml If you just wanted remove error use
<?php
$xml = @simplexml_load_file('http://radiojoven.6te.net/NowOnAir.xml');
if ($xml !== false)
{
$artist = urlencode($xml->Event->Song->Artist['name']);
$url = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=$artist&api_key=50ac27433c63f7298064f434f4ef6d15");
$largeImage = $url->xpath('/lfm/artist/image[@size="mega"]')[0];
echo '<img src="'.$largeImage.'" ';
?>width="100%" height="100%" /><?php
}
?>
Upvotes: 1