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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
moran1409 Posted February 23, 2011 Author Share Posted February 23, 2011 THANKS PaulRyan your solution worked Quote Link to comment 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. Quote Link to comment 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.