我正在尝试创建一个博客系统,我想将博客文章数据保存到 mysql 但很少混淆如何清理或清理数据这里是我尝试过的
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
return $data;
}
现在,当我通过 ajax 发布博客数据时,它看起来像
<h1 class="text-center">
Write the titles of article here
</h1>
然后我清理帖子数据并回显它
echo $title = mysqli_real_escape_string($connecDB, test_input($_POST['page__title']));
然后这是我得到的回应
\r\n Write the titles of article here\r\n
我想知道为什么我在响应中得到这些 \r\n 我怎样才能摆脱它们,这是清理 html 帖子的最佳方式
注意:我想将数据保存为 mysql 中的 html
我已经有一个正则表达式,可以找到样式和脚本标签并删除它,我也尝试删除条形斜杠并尝试添加 strip_tags 但我仍然得到 \r\n