在 MYSQL 中插入数据之前删除多余的字符? [英] removing extra characters before inserting data in MYSQL?

查看:35
本文介绍了在 MYSQL 中插入数据之前删除多余的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PHP 和 MYSQL 为我的网站创建一个简单的博客类型系统.

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

一切正常.但是,我现在面临的问题是,当我将数据插入到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: \

示例:

当我将图像链接/标签插入数据库时​​:我在我的数据库中得到以下内容:

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>

所以我试图在使用 PHP 将数据插入 mysql 之前删除这些额外的字符.

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);

然而,这段代码没有做任何事情.并且实际上停止了我的整个代码的工作,并且停止了我的代码将任何数据插入到 mysql 中.

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?

提前致谢.

推荐答案

尝试使用 stripslashes(字符串)

$body = stripslashes($body);

让我知道它是否有效.

这篇关于在 MYSQL 中插入数据之前删除多余的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆