PHP Tizag Tutorial-72
PHP Tizag Tutorial-72
$numberedString = "1234567890123456789012345678901234567890";
Display:
The position of 5 in our string was 4
The position of the second 5 was 14
By taking the first match's position of 4 and adding 1 we then asked strpos to begin searching after the last
match. The string it was actually sesarching after computing the offset wa: 6789012345... Letting us find the
second 5 in the string.
If we use our knowledge of PHP While Loops we can find every single 5 in our string numberedString with
just a few lines of code.
PHP Code:
$numberedString = "1234567890123456789012345678901234567890";
$offset = 0; // initial offset is 0
$fiveCounter = 0;