Created
March 21, 2011 10:58
-
-
Save mattattui/879298 to your computer and use it in GitHub Desktop.
Escaping PHP output inside HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')?>"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).