Skip to content
PHP Logo

How can PHP variables be formatted to store HTML code without special characters?

When storing HTML code in PHP variables, special characters such as quotes and angle brackets can cause issues. To avoid this problem, you can use the `heredoc` syntax in PHP, which allows you to store multi-line strings without escaping special characters. This way, you can easily store HTML code in a variable without worrying about special characters interfering with the code.

php
$html = <<<HTML
<!DOCTYPE html>
<html>
<head>
    <title>Example Page</title>
</head>
<body>
    <h1>Welcome to my page!</h1>
</body>
</html>
HTML;