What is the usage of "preg_replace('/\x13\x00*$/', '', $plain_text);" ?

Recommended Answers

You might want to have a look at this to simplify learning of regular expressions.

Jump to Post

All 4 Replies

See the PHP preg_replace Manual for the full synopsis of that function. But in a nutshell, the code you've provided uses a regular expression to delete any instance within $plain_text of a new-line character which is followed by a null character (end-of-string), which in turn is followed by any amount of characters and another new line character.

thanks for your reply,
please tell me process undergone in "/\x13\x00*$/", if possible explain separately !

EDIT: It's not looking for a new line character, it's looking for a DC3 character.

It's what's known as a regular expression.

Basically, the two /s merely indicate the start and end of the regex. Just ignore them for now. \x13 is an escape sequence, basically meaning that instead of trying to find x13, PHP should try and find the character with the ASCII code of 13 (in hex). The same principle applies for the \x00 part - it's not trying to find \ and x00, but instead the character with the ASCII value of 0. The asterisk (*) means 'zero or more characters'. The '$' just means 'end of the line'.

So when this regular expression is put together, PHP will be searching for the entire pattern, in that order. I'm not very good at explaining this in an understandable manner, maybe someone else can clarify it. Or you might prefer to read about regular expressions on the web..

You might want to have a look at this to simplify learning of regular expressions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.