3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "This is a string\n with newline\n" . "\xC2\xA0" . "and special character\n"; $cleaned_string = preg_replace(['/\R/u', '/\xC2\xA0/u'], ['/n', ''], $string); var_dump($string, $cleaned_string);
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
string(55) "This is a string with newline  and special character " string(58) "This is a string/n with newline/n and special character/n"

preferences:
70.04 ms | 992 KiB | 4 Q