3v4l.org

run code in 500+ PHP versions simultaneously
<?php $input = '🧪 test'; $encodings = ['utf-8', 'utf-16', 'utf-32']; foreach ($encodings as $to) { var_dump([ 'to' => $to, 'mb_substr' => mb_substr($input, 3, 4, $to), 'iconv_substr' => iconv_substr($input, 3, 4, $to), 'substr' => substr($input, 3, 4), 'substr+utf8_encode' => substr(utf8_encode($input), 3, 4), 'substr+utf8_decode' => substr(utf8_decode($input), 3, 4) ]); }
Output for 7.3.32, 7.4.26, 7.4.33, 8.0.13, 8.5.1 - 8.5.7
Fatal error: Uncaught Error: Call to undefined function iconv_substr() in /in/I3lr4:11 Stack trace: #0 {main} thrown in /in/I3lr4 on line 11
Process exited with code 255.
Output for 8.4.1 - 8.4.22, 8.5.0
Deprecated: Function utf8_encode() is deprecated since 8.2, visit the php.net documentation for various alternatives in /in/I3lr4 on line 13 Deprecated: Function utf8_decode() is deprecated since 8.2, visit the php.net documentation for various alternatives in /in/I3lr4 on line 14 array(6) { ["to"]=> string(5) "utf-8" ["mb_substr"]=> string(3) "est" ["iconv_substr"]=> string(3) "est" ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-16" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 Deprecated: Function utf8_encode() is deprecated since 8.2, visit the php.net documentation for various alternatives in /in/I3lr4 on line 13 Deprecated: Function utf8_decode() is deprecated since 8.2, visit the php.net documentation for various alternatives in /in/I3lr4 on line 14 array(6) { ["to"]=> string(6) "utf-16" ["mb_substr"]=> string(4) "es?" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-32" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 Deprecated: Function utf8_encode() is deprecated since 8.2, visit the php.net documentation for various alternatives in /in/I3lr4 on line 13 Deprecated: Function utf8_decode() is deprecated since 8.2, visit the php.net documentation for various alternatives in /in/I3lr4 on line 14 array(6) { ["to"]=> string(6) "utf-32" ["mb_substr"]=> string(0) "" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" }
Output for 8.2.0 - 8.2.30, 8.3.0 - 8.3.4, 8.3.6 - 8.3.31
Deprecated: Function utf8_encode() is deprecated in /in/I3lr4 on line 13 Deprecated: Function utf8_decode() is deprecated in /in/I3lr4 on line 14 array(6) { ["to"]=> string(5) "utf-8" ["mb_substr"]=> string(3) "est" ["iconv_substr"]=> string(3) "est" ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-16" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 Deprecated: Function utf8_encode() is deprecated in /in/I3lr4 on line 13 Deprecated: Function utf8_decode() is deprecated in /in/I3lr4 on line 14 array(6) { ["to"]=> string(6) "utf-16" ["mb_substr"]=> string(4) "es?" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-32" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 Deprecated: Function utf8_encode() is deprecated in /in/I3lr4 on line 13 Deprecated: Function utf8_decode() is deprecated in /in/I3lr4 on line 14 array(6) { ["to"]=> string(6) "utf-32" ["mb_substr"]=> string(0) "" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Function utf8_encode() is deprecated in /in/I3lr4 on line 13 Deprecated: Function utf8_decode() is deprecated in /in/I3lr4 on line 14 array(6) { ["to"]=> string(5) "utf-8" ["mb_substr"]=> string(3) "est" ["iconv_substr"]=> string(3) "est" ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-16" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 Deprecated: Function utf8_encode() is deprecated in /in/I3lr4 on line 13 Deprecated: Function utf8_decode() is deprecated in /in/I3lr4 on line 14 array(6) { ["to"]=> string(6) "utf-16" ["mb_substr"]=> string(4) "es?" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-32" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 Deprecated: Function utf8_encode() is deprecated in /in/I3lr4 on line 13 Deprecated: Function utf8_decode() is deprecated in /in/I3lr4 on line 14 array(6) { ["to"]=> string(6) "utf-32" ["mb_substr"]=> string(0) "" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" }
Output for 8.1.0 - 8.1.34
array(6) { ["to"]=> string(5) "utf-8" ["mb_substr"]=> string(3) "est" ["iconv_substr"]=> string(3) "est" ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-16" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 array(6) { ["to"]=> string(6) "utf-16" ["mb_substr"]=> string(4) "es?" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-32" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 array(6) { ["to"]=> string(6) "utf-32" ["mb_substr"]=> string(0) "" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" }
Output for 8.0.14 - 8.0.30
array(6) { ["to"]=> string(5) "utf-8" ["mb_substr"]=> string(3) "est" ["iconv_substr"]=> string(3) "est" ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-16" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 array(6) { ["to"]=> string(6) "utf-16" ["mb_substr"]=> string(2) "es" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Warning: iconv_substr(): Wrong encoding, conversion from "utf-32" to "UCS-4LE" is not allowed in /in/I3lr4 on line 11 array(6) { ["to"]=> string(6) "utf-32" ["mb_substr"]=> string(0) "" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" }
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12
array(6) { ["to"]=> string(5) "utf-8" ["mb_substr"]=> string(3) "est" ["iconv_substr"]=> string(3) "est" ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Notice: iconv_substr(): Detected an incomplete multibyte character in input string in /in/I3lr4 on line 11 array(6) { ["to"]=> string(6) "utf-16" ["mb_substr"]=> string(2) "es" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Notice: iconv_substr(): Detected an illegal character in input string in /in/I3lr4 on line 11 array(6) { ["to"]=> string(6) "utf-32" ["mb_substr"]=> string(0) "" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" }
Output for 7.3.33, 7.4.27 - 7.4.32
array(6) { ["to"]=> string(5) "utf-8" ["mb_substr"]=> string(3) "est" ["iconv_substr"]=> string(3) "est" ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Notice: iconv_substr(): Wrong charset, conversion from `utf-16' to `UCS-4LE' is not allowed in /in/I3lr4 on line 11 array(6) { ["to"]=> string(6) "utf-16" ["mb_substr"]=> string(2) "es" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" } Notice: iconv_substr(): Wrong charset, conversion from `utf-32' to `UCS-4LE' is not allowed in /in/I3lr4 on line 11 array(6) { ["to"]=> string(6) "utf-32" ["mb_substr"]=> string(0) "" ["iconv_substr"]=> bool(false) ["substr"]=> string(4) "� te" ["substr+utf8_encode"]=> string(4) "�§�" ["substr+utf8_decode"]=> string(3) "est" }

preferences:
116.65 ms | 1645 KiB | 4 Q