dsykx64220 2012-04-07 12:31
浏览 46
已采纳

htmlentities和htmlspecialchars拒绝处理字符串

Since the last update to PHP5 5.4.0-3 on my Debian box I noticed that some pages have empty fields where text from the MySQL database should be.

I played around a bit and found the problem.

<?php
$scselect = mysql_query("SELECT `name` FROM `forum_threads` WHERE `forum` = '1' ORDER BY `timestamp` DESC") or exit((mysql_error()));
    while ($scrow=mysql_fetch_array($scselect))
    {
        var_dump($scrow['name']);
        var_dump(htmlentities($scrow['name']));
    }
?>

strangely this is whats printed:

string(18) "php hu3: the Forum"
string(0) ""
string(18) "php hu2 score-rule"
string(0) ""
string(6) "php hu"
string(0) ""
string(15) "HU 8: Binarycnt"
string(0) ""

but if I use htmlentities with hardcoded content -> htmlentities("test"); it works like charm. Also if I do this:

var_dump("a".$scrow['name']);

it also says

string(0) ""

But it gets stranger. If I use htmlentities or htmlspecialchars with any other variable from the database it works just perfectly.

var_dump(htmlspecialchars($scrow['ID'])); // prints for example string(2) "87"

what can be the cause of this?

  • 写回答

3条回答 默认 最新

  • douda5706 2012-04-07 12:37
    关注

    Try this :

    htmlentities($scrow['name'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮