3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stripSpecialCharater($string) { return preg_replace(['/\s{2,}|[\t\R]/u', '/[^a-z\d\s&‚~§©ÂÃ⃀-]/ui'], [' ', ''], $string); //$string = iconv("Windows-1252","UTF-8",urldecode($string)); //$string = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $string); //return preg_replace('/[^a-zA-Z0-9ç&-©‚ƒ‘\s]/', '', $string); } $tests = ['12 34', 'adsf', 'co©', 'pound £']; foreach ($tests as $test) { echo "$test : "; var_export(stripSpecialCharater($test)); echo "\n"; }
based on Sviv8
Output for 7.4.0 - 7.4.16, 8.0.0 - 8.0.3
12 34 : Warning: preg_replace(): Compilation failed: escape sequence is invalid in character class at offset 11 in /in/VvVcc on line 4 NULL adsf : Warning: preg_replace(): Compilation failed: escape sequence is invalid in character class at offset 11 in /in/VvVcc on line 4 NULL co© : Warning: preg_replace(): Compilation failed: escape sequence is invalid in character class at offset 11 in /in/VvVcc on line 4 NULL pound £ : Warning: preg_replace(): Compilation failed: escape sequence is invalid in character class at offset 11 in /in/VvVcc on line 4 NULL
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.28
12 34 : '12 34' adsf : 'adsf' co© : 'co©' pound £ : 'pound '