Jump to content

Notice: Undefined offset: 1 in line 60


moran1409

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.