dongwei2882 2015-03-14 13:29
浏览 42
已采纳

在MYSQL中插入数据之前删除多余的字符?

I'm trying to create a simple blog type system for my site using PHP and MYSQL.

everything works fine. however, the issue that I am facing right now is that when I insert data into mysql database, it will have some extra characters.

the extra character that I am having the most difficulty with is this: \

Example:

when I insert an image link/tag into database: I get the following in my database:

<p><img alt=\"\" src=\"http://somedomain.com/images/9Image1.jpg\" /></p>

so I am trying to remove those extra characters before inserting the data into mysql using PHP.

for that, I tried using the following code:

$body = preg_replace("/\\\\\/", "", $body);

however, this code doesn't do anything. and in fact stops my entire code working and it stops my code from inserting any data into mysql.

Could someone please advise on this issue?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongyun9120 2015-03-14 13:36
    关注

    Try to use stripslashes(string)

    $body = stripslashes($body);
    

    Let me know if it works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址