Jump to content

[SOLVED] Remove slashes from (double and single quotes)


Dat

Recommended Posts

I'm new to this forum, but anyway. I have this variable with slashes using mysql_real_escape_string ()

I want to remove the slashes away from the variable without removing the \r\n ect.

 

$title = mysql_real_escape_string( $_POST['title'] );

 

In the variable that is currently being inputed: Miki Koishikawa\\\'s ordinary life...

Input in the database (as you may already know): Miki Koishikawa\'s ordinary life...

 

As you can see what is left is the \'s

 

I can't use stripslashes () because that would remove the \ from \r\n and that would leave me with rn.

 

Help? ???

It's very odd that you have \r and \n literally in your database strings.  How did this happen?

 

Also, there is no need to store the backslash in the database.  It looks like you have 2 levels of escaping there when you only need 1.

 

I suspect that what you need is this:

 

$title = mysql_real_escape_string(stripslashes($_POST['title']));

 

Then your input will not have the extra backslashes in the first place.

I got it...

function escape_data ($data) {
        global $dbc; // Need the connection
        if (ini_get('magic_quotes_gpc')) {
            $data = stripslashes($data);
        }
        return mysql_real_escape_string(trim($data), $dbc);
    }  

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.