PHP String tokenizer not working correctly

Posted by asdadas on Stack Overflow See other posts from Stack Overflow or by asdadas
Published on 2010-04-27T20:52:41Z Indexed on 2010/04/27 20:53 UTC
Read the original article Hit count: 328

I have no clue why strtok decided to break on me. Here is my code. I am tokenizing a string by dollar symbol $.

echo 'Tokenizing this by $: ',$aliases,PHP_EOL;
if(strlen($aliases) > 0)
{
    //aliases check
    $token = strtok($aliases, '$');
    while($token != NULL)
    {
        echo 'Found a token: ',$token,PHP_EOL;
        if(!isGoodLookup($token))
        {
            echo 'ERROR: Invalid alias found.',PHP_EOL;
            stop($db);
        }
        $goodAliasesList[] = $token;
        $token = strtok('$');
    }
    if($token == NULL)
        echo 'Found null token, moving on',PHP_EOL;
}

And this is my output:

Tokenizing this by $: getaways$aaa
Found a token: getaways
Found null token, moving on

str tok is not supposed to do this!! where is my aaa token!!

© Stack Overflow or respective owner

Related posts about php

Related posts about strtok