3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function strim($str) { $s1 = preg_replace('/[\pZ\pC]/muS',' ',$str); if(preg_last_error()) { $s1 = preg_replace('/[\pZ\pC]/muS',' ', iconv("UTF-8", "UTF-8//IGNORE", $str)); if(preg_last_error()) { return trim(str_replace(array(' ',' ',' ',' ',' '), ' ', $str)); } } return trim(preg_replace('/ {2,}/muS', ' ', $s1)); } echo "=".strim(" b áóñÑ baba bab")."=";
based on 02Xuc
Output for 5.2.0 - 5.6.30, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.3.0alpha1
=b áóñÑ baba bab=
Output for 5.0.5 - 5.1.6
Fatal error: Call to undefined function preg_last_error() in /in/Jt5Y8 on line 5
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 2 in /in/Jt5Y8 on line 4 Fatal error: Call to undefined function preg_last_error() in /in/Jt5Y8 on line 5
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: preg_last_error() in /in/Jt5Y8 on line 5
Process exited with code 255.
Output for 4.4.0 - 4.4.4
Fatal error: Call to undefined function: preg_last_error() in /in/Jt5Y8 on line 5
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 2 in /in/Jt5Y8 on line 4 Fatal error: Call to undefined function: preg_last_error() in /in/Jt5Y8 on line 5
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 2 in /in/Jt5Y8 on line 4 Fatal error: Call to undefined function: preg_last_error() in /in/Jt5Y8 on line 5
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 2 in /in/Jt5Y8 on line 4 Fatal error: Call to undefined function: preg_last_error() in /in/Jt5Y8 on line 5