views:

124

answers:

2

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

strtok is not supposed to do this!! where is my aaa token!!

A: 

i havent tried other tokens, but i will now.

i tried this code in an isolated setting and it finds the aaa token fine. i am sending this over a post ajax request - it shouldnt make any difference. the output i have above is exactly what it outputs in the post request. so for some reason if i just have this code on some random php page, it can find all the tokens, but it cant where i actually have it on my page.

asdasd
+1  A: 

wow im dumb yes it calls strtok inside isgoodlookup(). thanks guys.

asdasda