Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 475
Ali Avatar asked Sep 27 '11 01:09

Ali


People also ask

How remove all special characters from a string in PHP?

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.

How do I remove a character from a string in laravel?

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.

What are the control characters in PHP?

Control characters are e.g. line feed, tab, escape.


2 Answers

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.

like image 136
Vincent Marmiesse Avatar answered Oct 04 '22 09:10

Vincent Marmiesse


Have you tried rtrim function

http://php.net/manual/en/function.rtrim.php

like image 44
junedkazi Avatar answered Oct 04 '22 08:10

junedkazi