问题
Example data in my database:
blabla<blabla
I use phpmyadmin and can see that the data has been input successfully.
However when I try to display the data what I get is:
blabla
NOT blabla<blabla
In other words, everything after the <
symbol does not display.
<?
while ($mouselist_row = mysql_fetch_array($mouselist)) {
$mouselist_commonstrain = mysql_real_escape_string($mouselist_row['Common_Strain']);
echo "$mouselist_commonstrain.";
}
?>
I tried using mysql_real_escape_string
.
Is there something in particular needed to display the <
?
thanks
回答1:
You want something like:
echo htmlspecialchars($mouselist_commonstrain);
(It needs to be HTML escaped.)
回答2:
try this
$mouselist_commonstrain = stripslashes(htmlspecialchars($mouselist_row['Common_Strain']));
回答3:
Your problem isn't escaping SQL but HTML. As answered in this question you can use htmlspecialchars
function.
来源:https://stackoverflow.com/questions/18455406/how-to-extract-data-from-mysql-that-contains-special-characters