Here is 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 type expressions:

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

Then an error occurs

PHP Notice: Undefined offset: 1 in ...

which points to the string:

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

Actually, how to fix the error?

UPD :

If $word contains: "There is no character in the given line ( $word )", then no error occurs, although there is no = sign.

    2 answers 2

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

    You are trying to access an item with an index of 1 , which does not exist, and that's an error.

    • Outdid ... =) - Valeriy Karchov
    • :) the main thing was trying to help, and who is the 1st, who is the last anyway. The answer will be taken at the discretion of the vehicle, and not according to the time :) - DemoS
    • If $word contains: "There is no character in the given line ( $word )", then no error occurs, although there is no = sign. - nick777
    • Reformulate the comment - nothing is clear - DemoS
    • Well, I tried to define the following text in $word : "Vasya went to the store and bought bread", i.e. text that does not contain the = sign, but I do not get an error. Why? - nick777

    In your row

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

    no "=", but because

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

    returns an array with one element, and therefore $ part [1] is undefined.

    • If $word contains: "There is no character in the given line ( $word )", then no error occurs, although there is no = sign. - nick777
    • And how is $word[$i] chosen? Is that a character in the $word string? - Valeriy Karchov