Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all the special characters like "RS" (record separator)

I want to ask what is the best way to use php to remove unwanted special characters like RS? because if I contain such characters in my xml document, it makes the client program parsing failed.

(the data source contains both english and chinese characters)

thx!!

like image 401
Katrin Avatar asked Nov 24 '25 14:11

Katrin


1 Answers

you can use strtr for all special characters codes (is very fast):

$output = strtr($input, "\x1E\x06", "  "); // Remove RS and ACK

(there is 2 chars inside the first and 2 spaces inside the second string)

or a range with preg_replace:

$output = preg_replace("/[\x1C-\x1F]/", "", $input); // Remove FS GS RS US
like image 143
Paulo H. Avatar answered Nov 27 '25 05:11

Paulo H.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!