Home php Error “PHP Notice: Undefined offset: 1 in…”

Error “PHP Notice: Undefined offset: 1 in…”

Author

Date

Category

Here’s the code:

$ word [$ i] = str_replace ("*", ",", $ word [$ i]) ;
 $ part = explode ("=", $ word [$ i]);
 $ part1 = str_replace ("|", "", $ part [0]);
 $ part2 = str_replace ("|", "", $ part [1]);

When executed, if $ word contains expressions like:

[674237234092340234-42348437436 ::? (*) (_) :; #! ""%) (_)] {^% # $ @ ## $ ^^ & amp; * (& amp; ~ @ GVY () (*) (IOU}

Then an error occurs

PHP Notice: Undefined offset: 1 in …

which points to a line:

$ part2 = str_replace ("|", "", $ part [1]);

Actually, how to fix the error?

UPD :


Answer 1, authority 100%

This line ($ word ) is missing the = sign, so after explode in the $ part array, you only have a value with a 0 key and the expression $ part2 = str_replace ("|", "", $ part [1]); .

You are trying to access an element at index 1 that does not exist, here is an error.


Answer 2, authority 60%

In your line

[674237234092340234-42348437436 ::? (*) (_) :; #! ""%) (_)] {^% # $ @ ## $ ^^ & amp; * (& amp; ~ @ GVY () (*) (IOU}

no “=”, so

explode ("=", $ word [$ i]);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions