Jump to content

Recommended Posts

The variable $ex is probably an array. So, the error is stating that there is no array index 3 value.

 

If that variable is being used to hold command line arguments, then maybe you're not invoking the script with the right number of arguments.

 

Also, the $ex[3] syntax is used with strings to get the fourth character in the string.

 

It's always best to use isset() to make sure an array index value is there before trying to use it.

 

Example:

 

$value = isset($ex[3]) ? $ex[3] : '';  // default to whatever value - in this case I use an empty string ('')

// Then use $value

 

 

Another example:

 

if (isset($ex[3])) {

    $cmd = str_replace(array(chr(10), chr(13)), '', $ex[3]);

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/86843-solved-random-error/#findComment-443859
Share on other sites

because i have another question..

 

I was just trying to work it out before i posted it

 

$first = str_replace(":", '', $ex[3]);

$string = "$first"." $ex[4]"." $ex[5]";

 

i have that there, and im getting the same error, i no how to fix it but unsure of exactly the right code

 

if(isset($ex[5])) {
$string = "$first"." $ex[4]"." $ex[5]";
}
elseif(!isset($ex[5])) {
$string = "$first"." $ex[4]";
}
elseif(!isset($ex[4])) {
$string = "$first";
}

 

that didn't seem to work? i still get PHP Notice:  Undefined offset:  4 in C:\Inetpub\wwwroot\bot.php on line 82

 

but not undefined offser: 5 anymore, so one of them must be working but no the one with $ex[4]

Link to comment
https://forums.phpfreaks.com/topic/86843-solved-random-error/#findComment-443878
Share on other sites

its not an error.

 

its just telling you that you hadn't previously assigned that index.

 

If it gives you the expected results, ignore it or turn off notices.

 

Yes it's not an error but a notice, however, it's an indication of poor coding practices or bad logic. IMO, these should never be just ignored. The code/logic should be changed to handle not having an index defined properly.

 

Kingy, just do it the way I showed. Here's an example:

<?php

$first  = isset($ex[3]) ? str_replace(":", '', $ex[3]) : '';
$second = isset($ex[4]) ? $ex[4] : '';
$third  = isset($ex[5]) ? $ex[5] : '';

$string = $first . ' ' . $second . ' ' . $third;  // I assume you still want the spaces in between
?>

 

You still need to check your logic of why the indexes are empty (not defined). If you know why, that's fine.

 

 

Link to comment
https://forums.phpfreaks.com/topic/86843-solved-random-error/#findComment-443884
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.