How can I remove the ETX character (0x03) from the end of a string? I'd either like a function, otherwise I can write a regular expression, all I want to know is how to match the ETX character in a regular expression? trim()
doesn't work.
One useful function that can be used to remove special characters from a string is the str_replace() function. The empty string must be used to the replace character in this function to remove the specified character. The syntax of this function is given below. The str_replace() function can take four arguments.
The ltrim() function removes whitespace or other predefined characters from the left side of a string. Related functions: rtrim() – Removes whitespace or other predefined characters from the right side of a string. trim() – Removes whitespace or other predefined characters from both sides of a string.
Control characters are e.g. line feed, tab, escape.
To complete Charles' answer, I had a case where the ETX character was not at the end of the line so I had to use the following code:
$string = preg_replace('/\x03/', '', $string);
Just remove the $ sign.
Have you tried rtrim function
http://php.net/manual/en/function.rtrim.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With