Skip to content

Instantly share code, notes, and snippets.

@mattattui
Created March 21, 2011 10:58
Show Gist options
  • Save mattattui/879298 to your computer and use it in GitHub Desktop.
Save mattattui/879298 to your computer and use it in GitHub Desktop.
Escaping PHP output inside HTML
Instead of:
<input type="text" name="name" value="<?php echo $name; ?>">
Use:
<input type="text" name="name"
value="<?php echo htmlspecialchars($name, ENT_QUOTES, 'UTF-8')?>">
@mattattui
Copy link
Author

See http://inanimatt.com/php-output-escaping.php for explanation

Obviously if you're outputting to a page that isn't UTF-8, then change the last argument to whatever's appropriate. If you miss it out, PHP assumes ISO-8859-1 (strictly speaking, Windows-1252).

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