CakeFest 2025 Madrid: The Official CakePHP Conference

Voting

: six minus two?
(Example: nine)

The Note You're Voting On

loretoparisi at gmail dot com
2 years ago
A multi-byte safe preg_match_all that fixes capture offsets when using PREG_OFFSET_CAPTURE on utf-8 strings

<?php
function mb_preg_match_all($pattern, $subject, &$matches = null, $flags = 0, $offset = 0) {
$out=preg_match_all($pattern, $subject, $matches, $flags, $offset);
if(
$flags & PREG_OFFSET_CAPTURE && is_array($matches) && count($matches)>0) {
foreach (
$matches[0] as &$match) {
$match[1] = mb_strlen(substr($subject, 0, $match[1]));
}
}
return
$out;
}
?>

<< Back to user notes page

To Top