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

在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.

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

一切正常。 但是,我现在面临的问题是,当我将数据插入到mysql数据库中时,它会有一些额外的字符。 p>

我最困难的额外字符是 这个: \ code> p>

示例: p>

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

 &lt; p&gt;&lt; img alt = \“\”src = \“http://somedomain.com/images/9Image1.jpg \”/  &gt;&lt; / p&gt; 
  code>  pre> 
 
 

因此我尝试在使用PHP将数据插入mysql之前删除这些额外的字符。 p>

为此,我尝试使用以下代码: p>

  $ body = preg_replace(“/ \\\\\ /”,“”,$ body); \  n  code>  pre> 
 
 

但是,此代码不执行任何操作。 并且实际上阻止了我的整个代码工作,它阻止我的代码插入任何数据到mysql。 p>

有人可以就此问题提出建议吗? p>

提前致谢。 p> div>

Try to use stripslashes(string)

$body = stripslashes($body);

Let me know if it works.