PHP String Escape and Unescape Tool

Escape plain text for use inside PHP single-quoted or double-quoted string literals, or decode supported PHP-style escape sequences back into readable text. Quotes, backslashes, line breaks and control characters are processed locally in your browser.

Processed locally in your browser

Escape raw text for a PHP string literal or decode supported PHP-style escape sequences.

PHP single-quoted and double-quoted strings interpret backslash sequences differently.

Advanced options

Unicode normalization is optional and may change how some characters are represented.

Escape or unescape a PHP string

This PHP string escape tool converts plain text into escaped content suitable for PHP string literals, or decodes supported PHP-style escape sequences back to readable text. It handles quotes, backslashes, common control characters and dollar signs in double-quoted strings. The converter treats input as text and never executes PHP code, evaluates variables or runs expressions.

PHP escape examples

Plain-text input:

User "admin"
Path: C:\Tools\Unicode
Price: $10

Escaped for a PHP double-quoted string:

User \"admin\"\nPath: C:\\Tools\\Unicode\nPrice: \$10

PHP code example:

$message = "User \"admin\"\nPath: C:\\Tools\\Unicode\nPrice: \$10";

Single-quoted PHP example:

$message = 'It\'s stored in C:\\Tools\\Unicode';

PHP single-quoted vs double-quoted strings

PHP interprets escape sequences differently depending on the delimiter. Double-quoted strings interpret common escape sequences and variable interpolation, so literal dollar signs should be escaped when the content must remain text. Single-quoted strings are simpler: only backslash and single quote need special treatment.

SequenceSingle-quoted stringDouble-quoted string
\\Decoded as one backslash.Decoded as one backslash.
\'Decoded as a single quote.Preserved as a backslash plus quote by this tool unless single-quoted mode is selected.
\"Preserved literally.Decoded as a double quote.
\nPreserved as backslash plus n.Decoded as a line feed.
\tPreserved as backslash plus t.Decoded as a tab.
\$Preserved as backslash plus dollar sign.Decoded as a literal dollar sign.

How to escape quotes and backslashes in PHP

Escape double quotes inside double-quoted PHP strings, single quotes inside single-quoted PHP strings, and backslashes where a literal backslash must survive the PHP parser. In double-quoted strings, escape dollar signs when user-provided text such as $10 must not be interpreted as variable interpolation.

How to use the PHP string converter

  1. Choose Escape or Unescape.
  2. Select Double-quoted string or Single-quoted string.
  3. Paste the text or escaped PHP string content.
  4. Run the converter, then copy or download the result.
  5. Use normalization only when you intentionally want to change the Unicode representation before escaping.

PHP escape sequences supported by this tool

Double-quoted mode supports \\, \", \$, \n, \r, \t, \v, \e, \f and generated \xHH escapes for other C0 controls. Single-quoted mode supports \\ and \'. Unsupported backslash sequences are preserved instead of executed or guessed.

PHP addslashes vs string escaping

addslashes() adds backslashes before selected characters, but it is not a complete serializer and it is not a substitute for SQL parameterization, HTML escaping, JSON encoding or context-aware output encoding. This page is for PHP string literal content, not database or browser security boundaries.

Privacy and local processing

This tool processes text with JavaScript directly in your browser. Your input is not submitted to the server. The converter treats input as text only and does not execute PHP code, evaluate variables or run expressions.

Frequently asked questions

How do I escape a string in PHP?

Choose the PHP string type, paste raw text, then run Escape. The tool returns escaped string content for that delimiter style.

How do I escape quotes in a PHP string?

Escape double quotes as \" inside double-quoted strings and single quotes as \' inside single-quoted strings.

How do I unescape a PHP string?

Choose Unescape and the matching string type. Supported PHP-style escape sequences are decoded back into text without executing PHP.

Are PHP single-quoted and double-quoted strings escaped differently?

Yes. PHP single-quoted strings only interpret \\ and \' specially, while double-quoted strings also interpret escapes such as \n, \t and \$.

What is the difference between addslashes and PHP string escaping?

addslashes() adds backslashes before selected characters, but it is not a universal serializer and does not replace SQL parameters, HTML escaping or JSON encoding.

Does this tool execute PHP code?

No. Input is treated as text only. The tool does not evaluate variables, run expressions or execute PHP code.

Is my PHP string stored or sent to a server?

No. This browser-local tool does not submit, store or log your input on UnicodeNow servers.

Related tools

Working with another format? Use the JSON Escape and Unescape tool for JSON string content, the JavaScript Escape and Unescape tool for JavaScript literals, or the Unicode Escape Converter for sequences such as \u00E9.

Unicode Escape Converter

Convert text to and from Unicode escape sequences and numeric entities.

DeveloperProcessed locally

XML Escape and Unescape

Escape and decode XML entities and numeric character references.

DeveloperProcessed locally

Related guides

Unicode vs UTF-8

Unicode defines characters and code points. UTF-8 encodes those code points as bytes for files, databases, web pages, APIs and network messages.