note 128591 added to function.preg-match-all
| From: | loretoparisi at gmail dot com | Date: | Wed, 07 Jun 2023 12:28:00 +0000 |
| Subject: | note 128591 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220548@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 151.42.143.160)
----
Manual Page -- https://php.net/manual/en/function.preg-match-all.php
Edit -- https://main.php.net/note/edit/128591
Del: integrated -- https://main.php.net/note/delete/128591/integrated
Del: useless -- https://main.php.net/note/delete/128591/useless
Del: bad code -- https://main.php.net/note/delete/128591/bad+code
Del: spam -- https://main.php.net/note/delete/128591/spam
Del: non-english -- https://main.php.net/note/delete/128591/non-english
Del: in docs -- https://main.php.net/note/delete/128591/in+docs
Del: other reasons-- https://main.php.net/note/delete/128591
Reject -- https://main.php.net/note/reject/128591
Search -- https://main.php.net/manage/user-notes.php