🧩 HTML2PHP
HTML2PHP : HTML to PHP Converter is a Visual Studio Code extension that allows you to instantly transform a static .html
file into a dynamic PHP template powered by a MySQL database.
It extracts specific HTML blocks (like titles, content, footers) and generates:
- A dynamic PHP file (
.php
) with database-backed content
- A SQL schema (
schema.sql
) to create and populate the extracted_content
table
✨ Features
- 🔍 Extracts elements with:
.extract-title
.extract-content
.extract-footer
.extract-article
- ⚙️ Assigns unique
id
attributes if missing
- 🐘 Generates:
yourfile.php
: pulls content from MySQL
schema.sql
: SQL file with custom database name
- Per-file tables (
index
, contact
, etc.)
- 🧑💻 Admin Panel:
- Login system (session-based)
- Page selector
- Live editor UI
- Clean styling (responsive)
📦 Installation
Install from the Visual Studio Code Marketplace or via the VS Code Extensions panel by searching: html2php
🚀 Usage
- Open a
.html
file
- Run the command:
> HTML to PHP: Convert HTML to Dynamic PHP
- Enter your desired database name
- The following will be generated:
yourfile.php
schema.sql
/admin
folder
🧠 Example
📁 Output Structure
index.php # Dynamic PHP file
schema.sql # SQL schema with inserts
/admin
├── login.php # Admin login screen
├── dashboard.php # Multi-page selector
├── edit.php # Content editor UI
└── css/style.css # Admin panel styling
<h1 id="main-title" class="extract-title">Welcome to Our Website</h1>
<section id="hero" class="extract-content">
<p>This is dynamic content.</p>
</section>
✅ output: index.php
<h1 id="main-title" class="extract-title">
<?php echo isset($content_data['main-title']) ? $content_data['main-title']['content'] : 'Welcome to Our Website'; ?>
</h1>
output: 'schema.sql'
CREATE DATABASE IF NOT EXISTS dynamic_content;
USE dynamic_content;
CREATE TABLE IF NOT EXISTS extracted_content (
id INT AUTO_INCREMENT PRIMARY KEY,
element_id VARCHAR(255) NOT NULL UNIQUE,
content TEXT NOT NULL
);
INSERT INTO extracted_content (element_id, content)
VALUES ('main-title', 'Welcome to Our Website');
🔐 Admin Panel
🧑💼 Login with credentials
📄 Select a page (e.g. index, contact)
📝 Edit and update dynamic content
💾 Changes reflect in real-time
🔒 Auth protected
🛡️ Notes
Elements without id get fallback values like extract_0, extract_1
Static content remains untouched
Tables are named after HTML files to support multi-page content management
🛠️ Developer Guide
Compile the Extension
npm run vscode:prepublish
Launch Extension in Dev Mode
F5 in VS Code
Package for Marketplace
npx vsce package
Publish to Marketplace
npx vsce publish