|
Posted by matt VanDeWalle on 10/21/26 11:26
Hello all.
I am new to this list but not to new to php although maybe the problem I
am having will prove otherwise
ok, I am writing a server(or trying to), Basically I am attempting to
write a chat type server in php. I cant seem to get it to realize that I
have typed more than one word, so execute the code within the if
statement. basic function is below, well what I am attempting to do
anyway, I have the str_word_count() defined as $word_count and $words for
the array of words that str_word_count($variable, 1) creates
ok, little piece of code is below
function commands($sock, $data)
{
$word_count = str_word_count($data);
$words = str_word_count($data, 1);
/* here is where the problems come in I think */
if(($word_count == 2) && ($data == '.quit'))
{
echo "you quit with a message of $data\n";
}
else
{
echo "quitting without saying anything...\n";
}
}
it seems like the code fragment above does absolutely nothing e.g
$word_count reverts to being empty once the if statement is hit. if I put
something in the function, but outside of the if statement like
echo "word_count was $word_count\n";
that works fine and returns an integer like it should
am I the only one who finds this little thing odd or am I missing
something that it is so simple it already sticks out to others as a big
glaring error?
any ideas?
matt
[Back to original message]
|