| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2017-07-23 08:44 UTC] nikic@php.net
 
-Assigned To:
+Assigned To: nikic
  [2017-07-23 11:00 UTC] nikic@php.net
 
-Status: Assigned
+Status: Closed
  [2017-07-23 11:00 UTC] nikic@php.net
  [2017-07-24 06:51 UTC] andxfiles at gmail dot com
  [2017-07-24 07:00 UTC] spam2 at rhsoft dot net
  [2017-07-24 22:40 UTC] andxfiles at gmail dot com
  | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 13:00:02 2025 UTC | 
Description: ------------ when calling mb_str*pos (stripos, strrpos etc.) functions using mb_internal_encoding before their call instead of passing the encoding as a parameter, those functions do not use the encoding provided, thus being way slower. As one can see in the actual results below, when using mb_internal_encoding, all functions become way faster except for mb_stripos. Test script: --------------- <?php $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_strlen("fdsfdssdfoifjosdifjosdifjosdij:ά", "UTF-8"); } $finishtime = microtime(true); echo "mb_strlen with parameter UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_stripos("fdsfdssdfoifjosdifjosdifjosdij:ά", "α", 0, "UTF-8"); } $finishtime = microtime(true); echo "mb_stripos with parameter UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_substr("fdsfdssdfoifjosdifjosdifjosdij:ά", $i, 1, "UTF-8"); } $finishtime = microtime(true); echo "mb_substr with parameter UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; mb_internal_encoding("UTF-8"); $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_strlen("fdsfdssdfoifjosdifjosdifjosdij:ά"); } $finishtime = microtime(true); echo "mb_strlen with mb_internal_encoding UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_stripos("fdsfdssdfoifjosdifjosdifjosdij:ά", "α", 0); } $finishtime = microtime(true); echo "mb_stripos with mb_internal_encoding UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; $starttime = microtime(true); for ($i=0; $i<100000; $i++) { $a = mb_substr("fdsfdssdfoifjosdifjosdifjosdij:ά", $i, 1); } $finishtime = microtime(true); echo "mb_substr with mb_internal_encoding UTF8: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>"; ?> Actual result: -------------- mb_strlen with parameter UTF8: 103.7 milliseconds mb_stripos with parameter UTF8: 1450.7 milliseconds mb_substr with parameter UTF8: 81.6 milliseconds mb_strlen with mb_internal_encoding UTF8: 39.2 milliseconds mb_stripos with mb_internal_encoding UTF8: 1435.3 milliseconds mb_substr with mb_internal_encoding UTF8: 48.5 milliseconds