- substr: documentation ( source)
- var_dump: documentation ( source)
- mb_strlen: documentation ( source)
- mb_ereg_search_pos: documentation ( source)
- mb_ereg_search_init: documentation ( source)
- mb_ereg_search_getregs: documentation ( source)
<?php
$string = 'jème lé ponés';
mb_ereg_search_init($string, '(?<=[ ^])\w+'); // Detect words
while ($pos = mb_ereg_search_pos()) {
$match = mb_ereg_search_getregs()[0];
$matchBasedOnPos = substr($string, $pos[0], $pos[1]);
if ($matchBasedOnPos !== $match) {
throw new \LogicException("Match based on position '{$matchBasedOnPos}' does not correspond to actual match '{$match}'");
}
var_dump(mb_strlen($matchBasedOnPos));
}