Skip to content
OnlineToolStudio

Add Slashes

runs in your browserno sign-upfree

Add a backslash before quotes, backslashes and NUL characters — like PHP addslashes(). Choose what to escape, then copy the result.

Slashes added

43 chars

About this tool

Add Slashes puts a backslash in front of characters that would break a quoted string: single quotes ('), double quotes ("), backslashes (\) and the NUL byte — exactly what PHP's addslashes() does. Untick the quotes you don't need, or also turn line breaks and tabs into \n and \t for code. The result updates as you type.

How to use

  1. Paste or type your text.
  2. Choose what to escape: single quotes, double quotes, NUL, and optionally line breaks and tabs.
  3. Copy the result or download it as a .txt file.

FAQ

Is this the same as PHP addslashes()?

With the default options, yes: it escapes ' " \ and NUL, and leaves everything else alone. The extra options (skipping a quote type, escaping line breaks) go beyond addslashes().

Should I use this to protect SQL queries?

No — for databases use prepared statements (parameters) instead of escaping by hand. Added slashes are fine for quick tests, strings in code, JSON or config files. For SQL text, see the SQL Escape tool.

Why are backslashes always escaped?

A backslash that is already in your text has to become \\, otherwise it would join the character after it when the text is read back, and Strip Slashes could not restore your original.

Can I go the other way?

Yes. Use the Add slashes / Strip slashes buttons at the top, or Swap to move the result into the input and switch direction — handy to check that the text comes back unchanged.

Is my text uploaded?

No. Escaping runs entirely in your browser, so your text never leaves your device.

Related tools

All tools