Skip to content

Instantly share code, notes, and snippets.

@iampava
Created March 28, 2018 12:50
Show Gist options
  • Save iampava/6e7d3698f5c15d756bdd429b623c0a38 to your computer and use it in GitHub Desktop.
Save iampava/6e7d3698f5c15d756bdd429b623c0a38 to your computer and use it in GitHub Desktop.
Reusable HTML "components" with PHP
<?php
function createHeader() {
return '
<header>
<h1>
<span class="emoji">๐Ÿš€</span>
TW Checklist
<span class="emoji">๐Ÿš€</span>
</h1>
</header>
';
}
?>
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<?php
include "./header.component.php";
echo createHeader();
?>
</body>
</html>
@JudahAragao
Copy link

When dealing with dynamic values, it is essential to ensure that this data is properly escaped to avoid security issues such as HTML or JavaScript injection. A recommended practice is to use the htmlspecialchars function, as shown in the example below:

<?php
    echo '<input type="hidden" value="' . htmlspecialchars($data) . '" />'."\n";
?>

This approach is described in the official PHP documentation: FAQ: htmlspecialchars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment