Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: nine minus five?
(Example: nine)

The Note You're Voting On

Axeia
11 years ago
Might be pointing out the obvious but if you'd rather use a for loop rather than a while (to keep the token strings on the same line for readability for example), it can be done. Added bonus, it doesn't put a $tok variable outside the loop itself either.
Downside however is that you're not able to manually free up the memory used using the technique mentioned by elarlang.

<?php
for($tok = strtok($str, ' _-.'); $tok!==false; $tok = strtok(' _-.'))
{
echo
"$tok </br>";
}
?>

<< Back to user notes page

To Top