How to remove control characters from string in PHP

1 Answer

0 votes
$string = "PHP\r C\r\n C++\t C#\f";

$string = preg_replace('/[\x00-\x1F\x7F]/', '', $string);

echo $string;





/*
run:

PHP C C++ C#

*/

 



answered Dec 2, 2023 by avibootz
...