3v4l.org

run code in 300+ PHP versions simultaneously
<?php function badwords_full($string, &$bad_references) { static $bad_counter; static $bad_list; static $bad_list_q; if(!isset($bad_counter)) { $bad_counter = 0; $bad_list = badwords_list(); $bad_list_q = array_map('preg_quote', $bad_list); } return preg_replace_callback('~('.implode('|', $bad_list_q).')~', function($matches) use (&$bad_counter, &$bad_references) { $bad_counter++; $bad_references[$bad_counter] = $matches[0]; return mb_substr($matches[0], 0, 1).str_repeat('&squf;', strlen($matches[0]) - 1); }, $string); } function badwords_list() { # spanish $es = array( "gallina", "ñoño" ); # english $en = array( "chicken", "horse" ); # join all languages $list = array_merge($es, $en); usort($list, function($a,$b) { return strlen($b) < strlen($b); }); return $list; } echo badwords_full('Hola en español eres un ñoño!', $bad);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/AnPJl on line 34 Hola en español eres un ñ&squf;&squf;&squf;&squf;&squf;!
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33
Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/AnPJl on line 36 Hola en español eres un ñ&squf;&squf;&squf;&squf;&squf;!
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Hola en español eres un ñ&squf;&squf;&squf;&squf;&squf;!

preferences:
112.52 ms | 410 KiB | 5 Q