Skip to content

Instantly share code, notes, and snippets.

@mattattui
Created March 21, 2011 10:54
Show Gist options
  • Save mattattui/879294 to your computer and use it in GitHub Desktop.
Save mattattui/879294 to your computer and use it in GitHub Desktop.
Escaping PHP output
Instead of:
<?php echo $name; ?>
Use:
<?php echo htmlspecialchars($name, ENT_NOQUOTES, 'UTF-8'); ?>
@mattattui
Copy link
Author

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

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