3v4l.org

run code in 300+ PHP versions simultaneously
<?php $foo = "🚁- Tour @exslagermaurice"; function is_ascii( $str ) { return ( bool ) !preg_match( '/[\x80-\xFF]/' , $str ); } /** * utf8_single_chr_html_encode( ) * * Converts a UTF-8 character to HTML Numbered Entity like &#123; * @since 1.0 * * @param string $chr The Unicode character to be encoded as numbered entity * @return string HTML numbered entity */ function utf8_single_chr_html_encode( $chr ) { return '&#' . utf8_ord( $chr ) . ';'; } /** * utf8_html_encode( ) * * Converts a UTF-8 string to a series of * HTML Numbered Entities like &#123;&#39;&#1740;... * @since 1.0 * * @param string $str The Unicode string to be encoded as numbered entities * @return string HTML numbered entities */ function utf8_html_encode( $str ) { return implode( array_map( 'utf8_single_chr_html_encode' , mb_split( $str ) ) ); } var_dump(mb_detect_encoding($foo)); var_dump(utf8_html_encode($foo));
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
string(5) "UTF-8" Fatal error: Uncaught ArgumentCountError: mb_split() expects at least 2 arguments, 1 given in /in/pEQK6:36 Stack trace: #0 /in/pEQK6(36): mb_split('\xF0\x9F\x9A\x81- Tour @exs...') #1 /in/pEQK6(41): utf8_html_encode('\xF0\x9F\x9A\x81- Tour @exs...') #2 {main} thrown in /in/pEQK6 on line 36
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
string(5) "UTF-8" Warning: mb_split() expects at least 2 parameters, 1 given in /in/pEQK6 on line 36 Warning: array_map(): Expected parameter 2 to be an array, bool given in /in/pEQK6 on line 36 Warning: implode(): Argument must be an array in /in/pEQK6 on line 36 NULL
Output for 5.2.5 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33
string(5) "UTF-8" Warning: mb_split() expects at least 2 parameters, 1 given in /in/pEQK6 on line 36 Warning: array_map(): Argument #2 should be an array in /in/pEQK6 on line 36 Warning: implode(): Argument must be an array in /in/pEQK6 on line 36 NULL
Output for 4.3.4 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.4
string(5) "UTF-8" Warning: mb_split() expects at least 2 parameters, 1 given in /in/pEQK6 on line 36 Warning: array_map(): Argument #2 should be an array in /in/pEQK6 on line 36 Warning: implode(): Argument to implode must be an array. in /in/pEQK6 on line 36 NULL
Output for 4.3.2 - 4.3.3
string(5) "UTF-8" Fatal error: Call to undefined function: mb_split() in /in/pEQK6 on line 36
Process exited with code 255.
Output for 4.3.0 - 4.3.1
string(5) "UTF-8" Fatal error: Call to undefined function: mb_split() in /in/pEQK6 on line 36

preferences:
217.92 ms | 401 KiB | 366 Q