DEVELOPER TOOLS / ONLINE UTILITY

PHP String Escape Tool

Convert ordinary text into a PHP single-quoted string literal, escaping backslashes and apostrophes using PHP string rules.

FREE ONLINE TOOL

PHP String Escape Tool

Runs in your browser
Generates a PHP single-quoted string literal only. It is not SQL, HTML, JavaScript, or shell escaping.
OVERVIEW

What is PHP String Escape Tool?

PHP single-quoted strings have a deliberately small set of escape sequences: a backslash and a single quote must be escaped. This tool prepares a literal representation of text for examples and source-code generation. It does not make text safe for SQL, HTML, JavaScript, shell commands, or other contexts.

What can you use it for?

  • Create a PHP string literal for a code example or configuration snippet.
  • Escape apostrophes and backslashes before placing sample text in PHP source code.
  • Compare the original text with the generated PHP representation.

How to use this tool

  1. Paste the text you want to represent in PHP.
  2. Select Escape as PHP single-quoted string.
  3. Review the generated literal, including its surrounding single quotes.
  4. Copy the output and review it in the context of your PHP source code.

Example input

Load this text to see how an apostrophes and backslashes are represented in a PHP single-quoted string.

It's PHP\tools!

Tips and things to know

  • In PHP single-quoted strings, a backslash and an apostrophe are the only special escape cases.
  • This is source-code escaping, not output escaping or input sanitization.
  • Use PDO prepared statements for SQL values; never build SQL by concatenating escaped strings.
  • For HTML output, use htmlspecialchars() with the correct flags and encoding.

Frequently asked questions

Does this protect a string for SQL?

No. Use parameterized queries with PDO. PHP string escaping is unrelated to SQL injection prevention.

Does it escape double quotes?

Double quotes do not need escaping inside a PHP single-quoted string.

Does it execute PHP?

No. The browser creates a PHP code snippet as text; no PHP code is executed.