3v4l.org

run code in 200+ PHP versions simultaneously
<?php function ordutf8_step1(string $char) : int { $code = ord(substr($char, 0, 1)); if ($code >= 128) { if ($code < 224) $bytesnumber = 2; else if ($code < 240) $bytesnumber = 3; else if ($code < 248) $bytesnumber = 4; $codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0); $offset = 0; for ($i = 2; $i <= $bytesnumber; $i++) { $offset ++; $code2 = ord(substr($char, $offset, 1)) - 128; $codetemp = $codetemp * 64 + $code2; } $code = $codetemp; } return $code; } function ordutf8_step2(string $char) : int { $code = ord(substr($char, 0, 1)); if ($code >= 128) { $count = 0; if ($code < 224) { $bytesnumber = 2; } else if ($code < 240) { $bytesnumber = 3; $count = 32; } else if ($code < 248) { $bytesnumber = 4; $count = 48; } $codetemp = $code - 192 - $count; $offset = 0; for ($i = 2; $i <= $bytesnumber; $i++) { $offset ++; $code2 = ord(substr($char, $offset, 1)) - 128; $codetemp = $codetemp * 64 + $code2; } $code = $codetemp; } return $code; } function ordutf8_step3(string $char) : int { $code = ord(substr($char, 0, 1)); if ($code >= 128) { $count = 0; if ($code < 224) { $bytes = 2; } else if ($code < 240) { $bytes = 3; $count = 32; } else if ($code < 248) { $bytes = 4; $count = 48; } $temp = $code - 192 - $count; for ($i = 1; $i < $bytes; $i++) { $code = $temp = $temp * 64 + ord(substr($char, $i, 1)) - 128; } } return $code; } function ordutf8_step4(string $char) : int { $code = ord(substr($char, 0, 1)); if ($code > 127) { $bytes = 2; $count = 0; if ($code > 223){ $bytes = 3; $count = 32; } if ($code > 239){ $bytes = 4; $count = 48; } $temp = $code - 192 - $count; for ($i = 1; $i < $bytes; $i++) { $code = $temp = $temp * 64 + ord(substr($char, $i, 1)) - 128; } } return $code; } function ordutf8_step5(string $char) : int { $code = ord(substr($char, 0, 1)); if ($code > 239){ return ((($code - 240) * 64 + ord(substr($char, 1, 1)) - 128) * 64 + ord(substr($char, 2, 1)) - 128) * 64 + ord(substr($char, 3, 1)) - 128; } if ($code > 223){ return (($code - 224) * 64 + ord(substr($char, 1, 1)) - 128) * 64 + ord(substr($char, 2, 1)) - 128; } if ($code > 127) { return ($code - 192) * 64 + ord(substr($char, 1, 1)) - 128; } return $code; } $cicles = 100000; $char = 'ݟ'; $time = -microtime(true); for($i = 0; $i < $cicles; $i++) { ordutf8_step1($char); } $time += microtime(true); echo $time; echo "\n"; $time = -microtime(true); for($i = 0; $i < $cicles; $i++) { ordutf8_step2($char); } $time += microtime(true); echo $time; echo "\n"; $time = -microtime(true); for($i = 0; $i < $cicles; $i++) { ordutf8_step3($char); } $time += microtime(true); echo $time; echo "\n"; $time = -microtime(true); for($i = 0; $i < $cicles; $i++) { ordutf8_step4($char); } $time += microtime(true); echo $time; echo "\n"; $time = -microtime(true); for($i = 0; $i < $cicles; $i++) { ordutf8_step5($char); } $time += microtime(true); echo $time;
based on rcBFZ
Output for 7.2.0
0.02045202255249 0.018801927566528 0.016613006591797 0.016923189163208 0.012379169464111
Output for 7.1.12
0.026569128036499 0.0260910987854 0.023787975311279 0.024173974990845 0.019996881484985
Output for 7.1.11
0.027163028717041 0.027786016464233 0.024754047393799 0.024968147277832 0.019365787506104
Output for 7.1.10
0.028234004974365 0.025413990020752 0.024276971817017 0.024445056915283 0.019093990325928
Output for 7.1.9
0.026643037796021 0.026943206787109 0.023591995239258 0.028317928314209 0.019414901733398
Output for 7.1.8
0.026262998580933 0.027080774307251 0.023120164871216 0.02330207824707 0.018908977508545
Output for 7.1.7
0.028800010681152 0.025611162185669 0.024365186691284 0.024157047271729 0.020451068878174
Output for 7.1.6
0.027093887329102 0.025550842285156 0.024270057678223 0.023844957351685 0.01998496055603
Output for 7.1.5
0.025639057159424 0.025228977203369 0.023010015487671 0.02369213104248 0.022097110748291
Output for 7.1.4
0.026180028915405 0.025040149688721 0.025044202804565 0.024264097213745 0.020194053649902
Output for 7.1.3
0.026498079299927 0.025822162628174 0.022566080093384 0.024682998657227 0.018401145935059
Output for 7.1.2
0.026325941085815 0.025099992752075 0.02321195602417 0.02306604385376 0.018589973449707
Output for 7.1.1
0.026548147201538 0.024827003479004 0.022743940353394 0.023888826370239 0.019051074981689
Output for 7.1.0
0.025886058807373 0.02304220199585 0.021929025650024 0.022469043731689 0.017795085906982
Output for 7.0.26
0.027341842651367 0.026918172836304 0.026648044586182 0.025861024856567 0.020913124084473
Output for 7.0.25
0.026969909667969 0.02540111541748 0.024224042892456 0.024006843566895 0.019665956497192
Output for 7.0.24
0.028918981552124 0.026890993118286 0.024318933486938 0.023882150650024 0.018558025360107
Output for 7.0.23
0.030834197998047 0.026625156402588 0.024724006652832 0.02403998374939 0.018829107284546
Output for 7.0.22
0.027024984359741 0.025106906890869 0.024945020675659 0.024397134780884 0.018862009048462
Output for 7.0.21
0.026997089385986 0.025455951690674 0.02369499206543 0.023675918579102 0.018559217453003
Output for 7.0.20
0.02644419670105 0.024288892745972 0.022609949111938 0.023187160491943 0.018870115280151
Output for 7.0.19
0.024884939193726 0.024574995040894 0.021934032440186 0.022969961166382 0.017705917358398
Output for 7.0.18
0.026424169540405 0.023730993270874 0.022547006607056 0.023403882980347 0.018630027770996
Output for 7.0.17
0.025833129882812 0.024035930633545 0.023914098739624 0.022830963134766 0.01898193359375
Output for 7.0.16
0.025315046310425 0.023838043212891 0.022648096084595 0.02249813079834 0.018083095550537
Output for 7.0.15
0.025250911712646 0.025073051452637 0.023114919662476 0.023761034011841 0.01977801322937
Output for 7.0.14
0.027034044265747 0.025161981582642 0.025091886520386 0.023260831832886 0.019482135772705
Output for 7.0.13
0.028296947479248 0.024327993392944 0.024295091629028 0.025207996368408 0.019052028656006
Output for 7.0.12
0.025475025177002 0.024374961853027 0.023591041564941 0.023200988769531 0.018917083740234
Output for 7.0.11
0.025593042373657 0.024181842803955 0.02311897277832 0.023398160934448 0.017795085906982
Output for 7.0.10
0.025739192962646 0.028629064559937 0.024712800979614 0.023416996002197 0.018702030181885
Output for 7.0.9
0.025876998901367 0.025439023971558 0.022864818572998 0.023333787918091 0.018477916717529
Output for 7.0.8
0.049560070037842 0.024235010147095 0.023597002029419 0.023095846176147 0.017836093902588
Output for 7.0.7
0.025307178497314 0.024563074111938 0.02325177192688 0.023864030838013 0.018306016921997
Output for 7.0.6
0.025994062423706 0.025146961212158 0.02388596534729 0.023125886917114 0.018038034439087
Output for 7.0.5
0.025490045547485 0.023705005645752 0.021963834762573 0.022452116012573 0.017828941345215
Output for 7.0.4
0.026296138763428 0.023231029510498 0.021930932998657 0.023226976394653 0.018891096115112
Output for 7.0.3
0.031922101974487 0.032030820846558 0.024863004684448 0.023426055908203 0.019508838653564
Output for 7.0.2
0.024737119674683 0.023586988449097 0.022087097167969 0.022847175598145 0.018107175827026
Output for 7.0.1
0.026025056838989 0.024810075759888 0.023519992828369 0.023910999298096 0.019462108612061
Output for 7.0.0
0.026817798614502 0.024222135543823 0.023144006729126 0.023847103118896 0.018266201019287
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting '{' in /in/TWFLX on line 3
Process exited with code 255.