3v4l.org

run code in 300+ PHP versions simultaneously
<?php $acceptSpaces = true; $acceptUppercase = true; $text = 'El méu tëst'; // Replace non letter or digits by - $pattern = $acceptSpaces ? '~[^\\pL\d]+~u' : '~[^ \\pL\d]+~u'; $text = preg_replace($pattern, '-', $text); var_dump('preg replace', $text); // Trim $text = trim($text, '-'); var_dump('trim', $text); // Transliterate $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); var_dump('transliterate', $text); if(!$acceptUppercase) { // Lowercase $text = strtolower($text); } var_dump('lower', $text); // Remove unwanted characters $pattern = $acceptSpaces ? '~[^ -\w]+~' : '~[^-\w]+~'; $text = preg_replace($pattern, '', $text); var_dump('replace2', $text); var_dump( $text );
Output for 7.4.0 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
string(12) "preg replace" string(13) "El-méu-tëst" string(4) "trim" string(13) "El-méu-tëst" string(13) "transliterate" string(11) "El-m?u-t?st" string(5) "lower" string(11) "El-m?u-t?st" Warning: preg_replace(): Compilation failed: invalid range in character class at offset 6 in /in/gYp9H on line 37 string(8) "replace2" NULL NULL
Output for 7.3.32 - 7.3.33, 7.4.33, 8.0.13
string(12) "preg replace" string(13) "El-méu-tëst" string(4) "trim" string(13) "El-méu-tëst" Fatal error: Uncaught Error: Call to undefined function iconv() in /in/gYp9H:22 Stack trace: #0 {main} thrown in /in/gYp9H on line 22
Process exited with code 255.
Output for 7.3.0 - 7.3.31
string(12) "preg replace" string(13) "El-méu-tëst" string(4) "trim" string(13) "El-méu-tëst" string(13) "transliterate" string(11) "El-m?u-t?st" string(5) "lower" string(11) "El-m?u-t?st" string(8) "replace2" string(11) "El-m?u-t?st" string(11) "El-m?u-t?st"
Output for 5.5.10 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
string(12) "preg replace" string(13) "El-méu-tëst" string(4) "trim" string(13) "El-méu-tëst" string(13) "transliterate" string(11) "El-m?u-t?st" string(5) "lower" string(11) "El-m?u-t?st" Warning: preg_replace(): Compilation failed: invalid range in character class at offset 5 in /in/gYp9H on line 37 string(8) "replace2" NULL NULL
Output for 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.5.0 - 5.5.9
string(12) "preg replace" string(13) "El-méu-tëst" string(4) "trim" string(13) "El-méu-tëst" string(13) "transliterate" string(11) "El-m?u-t?st" string(5) "lower" string(11) "El-m?u-t?st" string(8) "replace2" string(9) "El-mu-tst" string(9) "El-mu-tst"
Output for 5.4.0 - 5.4.45
string(12) "preg replace" string(13) "El-méu-tëst" string(4) "trim" string(13) "El-méu-tëst" Fatal error: Call to undefined function iconv() in /in/gYp9H on line 22
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Warning: preg_replace(): Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 3 in /in/gYp9H on line 12 string(12) "preg replace" NULL string(4) "trim" string(0) "" string(13) "transliterate" string(0) "" string(5) "lower" string(0) "" string(8) "replace2" string(0) "" string(0) ""
Output for 4.4.5 - 4.4.9
string(12) "preg replace" string(13) "El-méu-tëst" string(4) "trim" string(13) "El-méu-tëst" Fatal error: Call to undefined function: iconv() in /in/gYp9H on line 22
Process exited with code 255.
Output for 4.4.0 - 4.4.4
string(12) "preg replace" string(13) "El-méu-tëst" string(4) "trim" string(13) "El-méu-tëst" Fatal error: Call to undefined function: iconv() in /in/gYp9H on line 22
Process exited with code 255.
Output for 4.3.11
Warning: preg_replace(): Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 3 in /in/gYp9H on line 12 string(12) "preg replace" NULL string(4) "trim" string(0) "" Fatal error: Call to undefined function: iconv() in /in/gYp9H on line 22
Process exited with code 255.
Output for 4.3.2 - 4.3.10
Warning: Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 3 in /in/gYp9H on line 12 string(12) "preg replace" NULL string(4) "trim" string(0) "" Fatal error: Call to undefined function: iconv() in /in/gYp9H on line 22
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 3 in /in/gYp9H on line 12 string(12) "preg replace" NULL string(4) "trim" string(0) "" Fatal error: Call to undefined function: iconv() in /in/gYp9H on line 22

preferences:
374.77 ms | 402 KiB | 464 Q