About this tool
Convert HTML to PHP templates and convert PHP back to clean HTML with safe echo placeholders, variables, and asset path handling.
The HTML PHP Converter turns static HTML into a PHP template and back again: HTML to PHP rewrites every {{ placeholder }} as <?= htmlspecialchars($var, ENT_QUOTES, 'UTF-8') ?>, prepends a <?php declare(strict_types=1); ?> block declaring each variable, and makes root-relative src/href/action paths base-path aware by prefixing $basePath. PHP to HTML runs the same mapping in reverse, stripping the config block and converting echoes back to {{ }} placeholders so a designer can work in plain markup. Control-flow blocks such as <?php if ... ?> are kept as HTML comments so nothing is lost in translation.
Open HTML PHP Converter on AltFTool — it loads instantly in your browser.
Choose the HTML to PHP or PHP to HTML card, then paste markup under "Source code" or press Upload code for a .html, .htm, .php, .phtml or .txt file.
Switch the conversion options: Safe echoes, Strict types, Base-path assets and Add PHP block for HTML to PHP; Strip config, Echo placeholders, Logic as comments and PHP comments for the reverse.
Press Download in the Generated PHP panel to save converted.php, or converted.html when running PHP to HTML.
Placeholders become htmlspecialchars($var, ENT_QUOTES, 'UTF-8'), which escapes single and double quotes as well as < > &, so pasted values cannot break out into markup.
Base-path rewriting skips protocol-relative //, https:, mailto:, tel:, data:, javascript: and #anchors, so external links and inline data URIs are left alone.
include/require lines and <?php ... ?> control blocks come back as HTML comments recording the original code, and the count is surfaced as a warning.
htmlspecialchars($var, ENT_QUOTES, 'UTF-8') on every placeholder. ENT_QUOTES is the flag that escapes both double and single quotes — the default would leave ' untouched, which is exactly the gap that breaks single-quoted HTML attributes — and naming UTF-8 explicitly avoids relying on the server's default charset.
Because they started with a single / , which breaks as soon as the app moves out of the domain root. The tool prefixes only those, declares $basePath = ''; at the top so behaviour is unchanged until you set it, and skips //, https:, mailto:, tel:, data:, javascript: and # values entirely.
No. Only echo forms map cleanly — <?= $x ?>, <?= htmlspecialchars($x, ENT_QUOTES, 'UTF-8') ?> and their <?php echo ...; ?> equivalents become {{ x }}. Anything else, including if/foreach and include/require, is preserved as an HTML comment listing the original code so you can port it deliberately.
Treat it as a starting point. The output escapes variables correctly and declares strict_types, but the variable values are placeholder strings derived from your key names, and any JavaScript, database access or logic that was in the source is left for you to review — the tool warns when it detects inline <script> or pre-existing PHP tags.
Add the HTML PHP Converter widget to your blog or website — free, responsive, no signup. Just keep the “Widget by AltFTool” credit link visible.
<iframe src="https://www.altftool.com/embed/widget/html-php-converter"
title="HTML PHP Converter — free AltFTool widget"
width="100%" height="640" style="border:0;border-radius:12px;overflow:hidden"
loading="lazy" referrerpolicy="no-referrer-when-downgrade" allow="clipboard-write"></iframe>
<p style="font-size:12px;margin:4px 0 0">Widget by <a href="https://www.altftool.com/tools/all/html-php-converter?utm_source=embed&utm_medium=widget" rel="nofollow">AltFTool — free online tools</a></p>