PHP 8.5.0 Alpha 4 available for testing

Voting

: five plus four?
(Example: nine)

The Note You're Voting On

frank at jkelloggs dot dk
20 years ago
Regarding the utf8_substr function from lmak: The pattern '/./u' doesn't match newline characters. This means that the substring from 0 to the total length of the string will miss the number of characters in the end matching the number of newlines in the string. To fix this one can add the s modifier (PCRE_DOTALL) in the pattern:

<?php
function utf8_substr($str,$start)
{
preg_match_all("/./su", $str, $ar);

if(
func_num_args() >= 3) {
$end = func_get_arg(2);
return
join("",array_slice($ar[0],$start,$end));
} else {
return
join("",array_slice($ar[0],$start));
}
}
?>

<< Back to user notes page

To Top