Reputation: 7752
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??
Upvotes: 2
Views: 981
Reputation: 3364
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.
Upvotes: 1