Text to unescape

PHP String Type:

Unescaped text

Why unescape PHP text?

Unescaping PHP strings is useful when you need to convert escaped PHP code back to its original form. This can be helpful when working with code generators, debugging PHP scripts, or processing PHP code that has been previously escaped.

Examples of PHP unescaping

Escaped text

$name = 'John O\'Connor';
$message = "Hello, this is a \"test\" message with \$variables";
$path = "C:\\Program Files\\PHP\\php.exe";
$multiline = "This is a\nmultiline string\nwith special chars: \', \", \\, \$var";
$heredoc = <<<EOD
This is a heredoc string
with \$variables and \"quotes\"
EOD;

Unescaped text (single)

$name = 'John O'Connor';
$message = "Hello, this is a \"test\" message with \$variables";
$path = "C:\Program Files\PHP\php.exe";
$multiline = "This is a\nmultiline string\nwith special chars: ', \", \, \$var";
$heredoc = <<<EOD
This is a heredoc string
with \$variables and \"quotes\"
EOD;

PHP String Types and Unescaping

Single-quoted Strings

In single-quoted strings, only a few escape sequences are recognized:

  • Escaped single quote (\') becomes '
  • Escaped backslash (\\) becomes \

Example: 'O\'Reilly' becomes 'O'Reilly'

Note: Other escape sequences like \n or \t are not interpreted in single-quoted strings.

Double-quoted Strings

Double-quoted strings support more escape sequences that are unescaped as follows:

  • Escaped double quote (\") becomes "
  • Escaped dollar sign (\$) becomes $
  • Escaped backslash (\\) becomes \
  • Escaped newline (\n) becomes a newline character
  • Escaped carriage return (\r) becomes a carriage return character
  • Escaped tab (\t) becomes a tab character
  • Escaped form feed (\f) becomes a form feed character
  • Escaped vertical tab (\v) becomes a vertical tab character
  • Escaped null byte (\0) becomes a null byte character

Example: "Path: C:\\Program Files\\PHP" becomes "Path: C:\Program Files\PHP"

Heredoc Syntax

Heredoc strings behave like double-quoted strings for unescaping:

$text = <<<EOD
This is a heredoc string with \$variables and \"quotes\"
EOD;

The same unescaping rules as double-quoted strings apply, converting escape sequences to their actual characters.

When to use PHP unescaping

  • When working with code generators that produce escaped PHP code
  • When debugging PHP scripts with escaped strings
  • When processing PHP code that has been previously escaped for storage or transmission
  • When converting between different string formats in PHP

Note:

This tool is designed to reverse the escaping process for PHP strings. It's particularly useful when working with PHP code generators or when you need to extract the original text from escaped PHP strings for further processing or display.

Other tools

Other tools available on this website: