AddSlashes to a String Online

Returns a string with backslashes in front of predefined characters - just like the PHP addslashes() function. The predefined characters are single quote ('), double quote ("), and backslash (\).

Choose what to escape

Frequently asked questions

What does addslashes actually do?

It puts a backslash in front of the characters that would otherwise end a string early: single quotes, double quotes, backslashes and the NUL byte.

Why is my backslash doubled?

The backslash is the escape character itself, so it has to be escaped to survive as a literal backslash. One in becomes two out.

Is addslashes safe against SQL injection?

No. It was never a security measure and it does not understand your database's rules. Use prepared statements with bound parameters, which keep the data out of the query text entirely.

What is the opposite of addslashes?

stripslashes, which takes the backslashes out again. This tool only adds them.

When is addslashes still the right tool?

For building a string you control, such as a config value, a generated code snippet or a literal you are pasting into a script. Not for anything a user typed on its way to a database.

Is this the same as the Escape Text tool?

Close, but not identical. Escape Text also escapes newlines and tabs as \n and \t, which is what you want for a string that has to sit on one line in source code.