3v4l.org

run code in 300+ PHP versions simultaneously
<?php _test(); function _test(){ // 不正な文字を削除する $cntnts = _illegal_character_remove('あいう😀えお'); $rplyCntnt = _illegal_character_remove('かき𠀋くけこ'); $pstvctgry = _illegal_character_remove('さしす🍺せそ'); $ngtvctgry = _illegal_character_remove('たち🍣つてと'); echo $cntnts; echo $rplyCntnt; echo $pstvctgry; echo $ngtvctgry; } function _illegal_character_remove($arg) { $repArr = array( "/\xd83c[\xdf00-\xdfff]/", "/\xd83d[\xdc00-\xde4f]/", "/\xd83d[\xde80-\xdeff]/", "/\xd7c9[\xde00-\xdeff]/", "/[\x2600-\x27BF]/", "/[\x203C|\x2047-\x2049|\x2753-\x2757|\x2761-\x2767][\xFE0E-\xFE0F]/", "/[0-9|*|#][\xFE0E-\xFE0F]\x20E3/", "/[0-9|*|#]\x20E3/", "/[\x23E9-\x23FA]/", "/[\x23CF|\x25B6|\x25C0|\x2B05-\x2B07|\x2194-\x21AA|\x2934-\x2935|\x2122|©|®|\x3030|\x25FC-\x25FE][\xFE0E-\xFE0F]/", "/\xA4B3/" ); $str = preg_replace($repArr, '', $arg); // 新たな文字列を用意 $retStr = ''; // 文字列を配列にしたものを用意 $strArr = str_split($str); // 1文字1文字ずつ処理 foreach ($strArr as $strS) { if (strlen($strS) < 4 && htmlspecialchars_decode("&#65038", ENT_QUOTES) != $strS && htmlspecialchars_decode("&#65039", ENT_QUOTES) != $strS) { $retStr .= $strS; } } $str = $retStr; return $str; } ?>
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Warning: preg_replace(): Compilation failed: range out of order in character class at offset 5 in /in/Ktj8h on line 35 Deprecated: str_split(): Passing null to parameter #1 ($string) of type string is deprecated in /in/Ktj8h on line 40 Warning: preg_replace(): Compilation failed: range out of order in character class at offset 5 in /in/Ktj8h on line 35 Deprecated: str_split(): Passing null to parameter #1 ($string) of type string is deprecated in /in/Ktj8h on line 40 Warning: preg_replace(): Compilation failed: range out of order in character class at offset 5 in /in/Ktj8h on line 35 Deprecated: str_split(): Passing null to parameter #1 ($string) of type string is deprecated in /in/Ktj8h on line 40 Warning: preg_replace(): Compilation failed: range out of order in character class at offset 5 in /in/Ktj8h on line 35 Deprecated: str_split(): Passing null to parameter #1 ($string) of type string is deprecated in /in/Ktj8h on line 40
Output for 8.0.1 - 8.0.30
Warning: preg_replace(): Compilation failed: range out of order in character class at offset 5 in /in/Ktj8h on line 35 Warning: preg_replace(): Compilation failed: range out of order in character class at offset 5 in /in/Ktj8h on line 35 Warning: preg_replace(): Compilation failed: range out of order in character class at offset 5 in /in/Ktj8h on line 35 Warning: preg_replace(): Compilation failed: range out of order in character class at offset 5 in /in/Ktj8h on line 35

preferences:
87.18 ms | 409 KiB | 5 Q