【问题标题】:Why script send /n?为什么脚本发送/n?
【发布时间】:2011-11-12 16:29:02
【问题描述】:

来源——

控制器 -

Model::factory('index')->send_comment(mysql_real_escape_string($name), mysql_real_escape_string($artcl_id), mysql_real_escape_string($text), mysql_real_escape_string(time()), mysql_real_escape_string($ip));
                        Model::factory('index')->update_comment_count($artcl_id);

在使用 trim() 函数检查 $_POST 数据之前,$text 是 trim($_POST['text'])。

但是当我写评论时-

Hello!

This is a comment!

到数据库脚本发送

Hello!/n/nThis is a comment!

在视图中-

<?php echo htmlspecialchars(nl2br($comment['text'])); ?>

错在哪里?

【问题讨论】:

    标签: php frameworks kohana


    【解决方案1】:

    我假设它发送了Hello!\n\nThis is a comment! 并且没有错误。
    一切正常

    【讨论】:

      【解决方案2】:

      假设 Col. Shrapnel 是正确的,并且您使用数据库模块(ORM 使用它,只是说)您不必花费精力自己逃避输入。但是,如果您想将未转义的输入发送到数据库,您将不得不花费精力。

      请参阅在整个数据库模块中使用的Database::quote()、Database::quote_column()、Database::quote_identifier() 和 Database::quote_table()。

      PS。始终验证输入。

      【讨论】:

        猜你喜欢
        • 2020-12-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-18
        • 2019-03-12
        • 1970-01-01
        • 1970-01-01
        • 2021-02-22
        相关资源
        最近更新 更多