PHP - Handling quote characters in HTML form input fields
by Subramanian[ Edit ] 2014-08-09 14:43:32
PHP - Handling quote characters in HTML form input fields :
In HTML, attribute values should be enclosed by double or single quotes. But a common source of errors and confusion arises when those values themselves contain double or single quotes.
This is especially common for form input fields, where the values might contain data obtained from a database or supplied previously by the user. This article looks at how to deal with this problem using PHP.
For Example :
<?php
$str = "GvSubhu's";
echo "<input type=text value=".$str." />";
?>
Output :
<input type='text' value='GvSubhu's' />
So we need to make some changes for php $str variable.
For Example :
<?php
$str = "GvSubhu's";
echo "<input type=text value=".htmlentities($str, ENT_QUOTES)." />";
?>
Output :
<input type="text" value='GvSubhu's' />