Search code examples
phpregexasciispecial-characterscontrol-characters

How to remove ETX character from the end of a string? (Regex or PHP)


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.


Solution

  • 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.