I\'m trying to populate a form with some data that contains special characters (e.g. single quote, double quote,<,>,?,\",\"\".~,,!@#$%^&*()_+}{\":?<<>,./;\'[.]
If you want to display it
echo htmlspecialchars($messge, ENT_QUOTES, 'UTF-8');
That's what I usually do.
Since the answers are difference:
htmlentities-vs-htmlspecialchars is worth checking out.
whats wrong with using a constant ?
<?php
define(foo,'<,>,?,","".~,,!@#$%^&*()_+}{":?<<>,./;');
$foo2="'[.]";
echo constant('foo').$foo2;
?>
you need to put the '[.]' into a variable, as a constant will break on a ' (single quote).
I normally use the following code, see htmlspecialchars
<?php echo htmlspecialchars($videoId, ENT_QUOTES | ENT_HTML5); ?>
This will prevent your tags from being broken by the echo:
<?php echo htmlentities($message); ?>