TERO
TERO

Reputation: 159

removing extra characters before inserting data in 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.

Upvotes: 0

Views: 674

Answers (1)

Thiago Elias
Thiago Elias

Reputation: 939

Try to use stripslashes(string)

$body = stripslashes($body);

Let me know if it works.

Upvotes: 4

Related Questions