how to extract data from mysql that contains special characters? [duplicate]

怎甘沉沦 提交于 2019-12-11 18:38:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!