HTML to PHP Converter

Wrap markup in PHP output statements without hunting for the quotes you forgot to escape.

HTML
PHP
Runs locally in your browser

About the HTML to PHP Converter

Dropping a block of markup into a PHP function means escaping it, and doing that by hand is where the afternoon goes: a double quote inside a class attribute ends the string, a dollar sign in a price becomes an undefined variable, and a stray backslash quietly disappears. This tool does the mechanical part and gives you four shapes to choose between.

The echo mode writes one statement per line of markup, which keeps diffs readable and lets you interleave PHP logic between lines later. Build a variable concatenates into a single string with .= and echoes it at the end, useful when the markup has to be returned rather than printed. Heredoc keeps the markup completely intact between <<<HTML and its closing label and still interpolates variables, so a template with $name placeholders keeps working. Nowdoc is the same layout with single quoted label and no interpolation at all, which is the right choice for markup that must survive byte for byte.

Escaping follows the mode. Double quoted output escapes backslashes, quotes and, when the option is on, dollar signs. Single quoted output escapes only backslashes and apostrophes and appends the newline separately, because PHP does not expand escape sequences inside single quotes. Heredoc mode refuses to run when a line of your markup begins with the closing label, since that would terminate the block early and produce a parse error further down the file. Long term, a template file or an output buffer beats a wall of echo statements, so treat this as the fast route rather than the architecture.

How to use

  1. Paste the markup you want to emit from PHP.
  2. Pick a Style: echo for short blocks, heredoc or nowdoc for whole templates.
  3. Set the Variable name if the default does not match your code.
  4. Leave Escape $ signs on unless the markup contains PHP variables you want interpolated.

Common questions

When should I use nowdoc instead of heredoc?
Whenever the markup contains dollar signs, curly braces or backslashes that must appear literally. Nowdoc performs no substitution at all.
Why does the tool refuse my heredoc?
A line in the markup starts with the closing label HTML, which would end the block early. Use the echo or variable mode for that input.
Does the output escape user data?
No, and it should not. This wraps static markup. Values coming from a request still need htmlspecialchars at the point where you insert them.
Can I leave the opening PHP tag off?
Yes. Untick that option when you are pasting into the middle of an existing file that is already in PHP mode.