moran1409 Posted February 23, 2011 Share Posted February 23, 2011 i get the error for this code: <?php $news = fopen("test.txt", "rb"); while (!feof($news) ) { $line = fgets($news); $parts = explode('=', $line); print $parts[0] . $parts[1]. "<BR>";//line 60!!! } fclose($news); ?> i know that this means that the array gets one argument instead of two but i do'nt know how to solve it... this code works fine in my localhost but not on the server Link to comment https://forums.phpfreaks.com/topic/228637-notice-undefined-offset-1-in-line-60/ Share on other sites More sharing options...
Pikachu2000 Posted February 23, 2011 Share Posted February 23, 2011 That means that $parts[1] doesn't exist, which would probably indicate that there is no hyphen in the string being explode()d. Link to comment https://forums.phpfreaks.com/topic/228637-notice-undefined-offset-1-in-line-60/#findComment-1178824 Share on other sites More sharing options...
PaulRyan Posted February 23, 2011 Share Posted February 23, 2011 Thats no Hyphen....thats an equals (=) sign but nonetheless, it doesn't exist. Try doing something like this: <?php $news = fopen("test.txt", "rb"); while (!feof($news) ) { $line = fgets($news); $parts = explode('=', $line); if(count($parts) == 2) { echo $parts[0] , $parts[1], '<br>'; } else { echo $parts[0], '<br>'; } } fclose($news); ?> Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/228637-notice-undefined-offset-1-in-line-60/#findComment-1178826 Share on other sites More sharing options...
kenrbnsn Posted February 23, 2011 Share Posted February 23, 2011 What's in the file being read? You could check to see if there are 2 items in the array before trying to print it: <?php $parts = explode('=', $line); if (count($parts) == 2) { print $parts[0] . $parts[1]. "<BR>"; } else { print $parts[0] . "<br>"; ?> You could also, use the implode function <?php echo implode('',$parts) . '<br>'; ?> If you just want to print the line without the "=', just do <?php echo str_replace('=','',line) . '<br>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/228637-notice-undefined-offset-1-in-line-60/#findComment-1178827 Share on other sites More sharing options...
moran1409 Posted February 23, 2011 Author Share Posted February 23, 2011 THANKS PaulRyan your solution worked Link to comment https://forums.phpfreaks.com/topic/228637-notice-undefined-offset-1-in-line-60/#findComment-1178854 Share on other sites More sharing options...
Pikachu2000 Posted February 23, 2011 Share Posted February 23, 2011 Thats no Hyphen....thats an equals (=) sign but nonetheless, it doesn't exist. I either need glasses or I need to change my screen resolution, one of the two. Hell, possibly both. Link to comment https://forums.phpfreaks.com/topic/228637-notice-undefined-offset-1-in-line-60/#findComment-1178858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.