note 55107 added to function.substr

From: Date: Mon, 25 Jul 2005 21:37:38 +0000
Subject: note 55107 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-92430@lists.php.net to get a copy of this message
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)); } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55107 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55107&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55107&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55107&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55107&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55107&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55107&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55107&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92430) next »