2

I hava a construct like this:

<?php
    $token=strtok($var,";");
    while($token!=false)
    {
        for($i=1;$i<=number_scores;$i++)
        {

            $score_token=strtok($var2,";");
            $k=0;
            while($score_token!=false)
            {
                $k++;
                $score_token=strtok(";");
            }
            $score_token=strtok($var3,";");
            while($score_token!=false)
            {
                $k--;
                $score_token=strtok(";");
            }
            echo $k;
         }
         $token=strtok(";");
     }
?>

This code is not working as expected as the string tokenizer is being updated by the inner tokenizers and the outer tokenizer is running only once. What is the work around for this??

1 Answer 1

1

The documentation on strtok says quite clearly that "To start over, or to tokenize a new string you simply call strtok with the string argument again to initialize it", and does not mention a way to have multiple parses going at once.

I would use explode for at least one of your parses, getting the tokens into an array which you can then examine at leisure.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.