tommyinnn Posted September 8, 2011 Share Posted September 8, 2011 Hello, my script worked great with no errors until I had to migrate to a new server, which is using cpanel/WHM, I have run Apache update and ensured curl is installed but I keep getting this in the error log. Here is part of the code, the error is PHP Notice: Undefined offset: 2 in /home/username/public_html/control/ajax/actions/currently_playing.php on line 59 and here is that section of code (line 59 is labled) // Diaplays when sever is online but no song title } else { $title = str_replace('\'', '`', $split[6]); $title = str_replace(',', ' ', $title); $title = "$title"; // Diaplays song } } if($title) { $tmp = explode(" - ", $title); $artist = trim(str_replace("`", "'", $tmp[0])); $album = trim(str_replace("`", "'", $tmp[1])); $title = trim(str_replace("`", "'", $tmp[2])); //LINE 59 HERE $request = $this->albumGetInfo($artist, $album); $img = $request["album"]["image"][1]["#text"]; Quote Link to comment https://forums.phpfreaks.com/topic/246714-undefined-offset/ Share on other sites More sharing options...
KevinM1 Posted September 8, 2011 Share Posted September 8, 2011 The notice is telling you that there isn't a $tmp[2]. Your array is shorter/has fewer elements than you think. Quote Link to comment https://forums.phpfreaks.com/topic/246714-undefined-offset/#findComment-1266903 Share on other sites More sharing options...
tommyinnn Posted September 8, 2011 Author Share Posted September 8, 2011 Sir thank you for your reply however this works 100% on a different server -- do you know what could be the difference, what can I install to correct this? The $tmp[2] missing means there is no title for the mp3 (uses last.fm api) - so what happens is when there is no title, nothing displays, when the mp3 does have a title in it's tag, all 4 items display (album artwork, title, artist and album) Quote Link to comment https://forums.phpfreaks.com/topic/246714-undefined-offset/#findComment-1266910 Share on other sites More sharing options...
JonnoTheDev Posted September 8, 2011 Share Posted September 8, 2011 The error reporting level differs between servers. When this code was on your other server, the error still existed however it did not show because of the error reporting level set in the server's php.ini file. You should always fix errors, however if you do not want NOTICE errors to be displayed you can add this to the very to of your script. <?php error_reporting(E_ALL & ~E_NOTICE); ?> If you have access to the server's php.ini file you can ammend the error reporting level globally there. Quote Link to comment https://forums.phpfreaks.com/topic/246714-undefined-offset/#findComment-1266940 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.