What is the purpose of addcslashes in php?

0

What is the addcslashes function for? I saw in the PHP manual but I did not understand.

    
asked by anonymous 18.01.2018 / 15:44

1 answer

1

According to the manual:

  

Returns a string with backslashes before characters   are listed in the charlist parameter.

Example:

php > echo addcslashes("Ola! Meu nome é Homer. Tudo bem?", "!.?");
Ola\! Meu nome é Homer\. Tudo bem\?

Normally the escape character () is used when you want to change the character's original direction.

For example, if you want to print the "\ n". The character \ has a special meaning (escape the next character). In this case, it turns the sequence into a line change. If it is executed:

echo "\n";

A line change will be printed. If you want to print (literally) \ n, you need to use \ n. It will be interpreted as follows:

: Look, the next character does not have the usual sense.

: My usual sense is to escape the next character, but the previous character has changed my meaning. Then I'll be interpreted as just a bar.

n: I'm just a n.

And as a result, "\ n" will be printed.

Returning to addcslashes

You specify the string and which characters you want to insert in the \ front, to change its usual meaning. It is usually used to escape strings for printing or processing.

    
18.01.2018 / 15:57