PHP Notice Undefined offset 1 with array when reading data

0 votes

I am getting this error :

PHP Notice:  Undefined offset: 1

This is the code that return the error:

$file_handle = fopen($path."/Summary/data.txt","r"); //open text file
$data = array(); // create new array map

while (!feof($file_handle) ) {
    $line_of_text = fgets($file_handle); // read in each line
    $parts = array_map('trim', explode(':', $line_of_text, 2)); 
    // separates line_of_text by ':' trim strings for extra space
    $data[$parts[0]] = $parts[1]; 
    // map the resulting parts into array 
    //$results('NAME_BEFORE_:') = VALUE_AFTER_:
}

 What causes this error? And what does this error mean?

Jun 9, 2022 in PHP by Kichu
• 19,040 points
1,340 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

Error:PHP Notice: Undefined offset: 1

Hello @kartik, Change $data[$parts[0]] = $parts[1]; to if ( ! isset($parts[1])) ...READ MORE

answered Oct 20, 2020 in PHP by Niroj
• 82,840 points
7,653 views
0 votes
1 answer

Error:“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

Hello @kartik, The best way for getting input string is: $value ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,840 points
37,524 views
0 votes
1 answer

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,314 views
–1 vote
1 answer
0 votes
1 answer

Notice: Undefined index: bid in C:\xampp\htdocs\userac\courier_management_system-master\courier_management_system-master\addstaff.php on line 130

Hello @saima , Before you extract values from $_POST ,$_SESSION, ...READ MORE

answered Sep 14, 2020 in PHP by Niroj
• 82,840 points
2,853 views
0 votes
1 answer

PHP __PHP_Incomplete_Class Object with my $_SESSION data

Hello @kartik, You just have to include the safestring.class.php before ...READ MORE

answered Nov 23, 2020 in PHP by Niroj
• 82,840 points
2,562 views
0 votes
0 answers

Undefined index error PHP

I'm getting this error: Notice: Undefined index: productid ...READ MORE

Jun 11, 2022 in PHP by narikkadan
• 63,600 points
545 views
0 votes
0 answers

PHP Fatal error: Using $this when not in object context

I am working on a new WebApp without ...READ MORE

Jun 18, 2022 in PHP by narikkadan
• 63,600 points
1,023 views
0 votes
0 answers

PHP - CodeIgniter - Invalid argument supplied for foreach()

I'm attempting to use CodeIgniter to create ...READ MORE

Jul 25, 2022 in PHP by Kithuzzz
• 38,000 points
1,038 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
1,560 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP