In words, I clear out the '!speak', 'adminuser' and 'adminpass' parts, then implode the array to a string, with each part seperated by a space. The first three characters of this string would be spaces (because there are three empty parts), which should be removed by the substr function.
$message should now be 'I AM A MACHINE'
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to make a function to let the bot say something.
!speak adminuser adminpass I AM A MACHINE
Then I want the bot to say: I AM A MACHINE
But how can I capture all words after the second argument as a single string? Normally you use $data->messageex[1];
But I want $data->messageex[3]; to be the whole sentence: I AM A MACHINE
I think this might work:
$msg = $data->messageex;
$msg[0] = '';
$msg[1] = '';
$msg[2] = '';
$message = substr( implode( ' ', $msg ), 3 );
In words, I clear out the '!speak', 'adminuser' and 'adminpass' parts, then implode the array to a string, with each part seperated by a space. The first three characters of this string would be spaces (because there are three empty parts), which should be removed by the substr function.
$message should now be 'I AM A MACHINE'
That would work. You might also do it this way:
$args = preg_quote("$data->messagex[0] $data->messagex[1] $data->messagex[2]");
$message = ereg_replace("^$args ", '' implode(' ', $data->messageex));