PHP 4.3.3
magic_quotes_gpc is on
I have a site where user input is taken from a form , displayed, re-edited, inserted to db etc.
The data would truncate on " so I assumed I needed a combination of addslashes and htmlspecialchars. However, the ENT_QUOTES doesn't seem to have an effect .
I tested with the following expecting the EN_QUOTE ones to translate both types of quotes:
if(isset($POST['preview'])){
$orig = $POST['inputText'];
$stripped=stripslashes($_POST['inputText']);
//typed: A'quote' is "<b>bold</b>
//Checked results from page source
echo htmlentities($orig)."<br> \n";
// Outputs: A \'quote\' is \"<b>bold</b>
echo htmlentities($orig, ENT_QUOTES)."<br> \n";
// Outputs: A \'quote\' is \"<b>bold</b>
echo htmlentities($stripped)."<br> \n";
// Outputs: A 'quote' is "<b>bold</b>
echo htmlentities($stripped, ENT_QUOTES)."<br>\n";
// Outputs: A 'quote' is "<b>bold</b>
echo htmlspecialchars($orig)."<br>\n";
// Outputs: A \'quote\' is \"<b>bold</b>
echo htmlspecialchars($orig, ENT_QUOTES)."<br>\n";
// Outputs: A \'quote\' is \"<b>bold</b>
echo htmlspecialchars($stripped)."<br>\n";
// Outputs: A 'quote' is "<b>bold</b>
echo htmlspecialchars($stripped, ENT_QUOTES)."<br>\n";
// Outputs: A 'quote' is "<b>bold</b>
}
else{
echo"<form action=\"entities.php\" enctype=\"application/x-www-form-urlencoded\" method=\"post\">";
echo"<input type=\"text\" name=\"inputText\">";
echo"<br><input type=\"submit\" name=\"preview\" value=\"Preview\">";
}
I expected the 'ENT_QUOTES' ones to change the single and double quotes.
Have I just misunderstood htmlspecialchars/htmlentities or is there another reason?