Jump to content

Undefined offset


tommyinnn

Recommended Posts

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"];

 

 

Link to comment
https://forums.phpfreaks.com/topic/246714-undefined-offset/
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/246714-undefined-offset/#findComment-1266910
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/246714-undefined-offset/#findComment-1266940
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.