Jump to content

[SOLVED] PHP keeps adding \ in front of text


ciber

Recommended Posts

I got an script I wrote to help with updating my rss feed, since I do it manually.

But I have a problem, when I click submit the text in the textbox <textbox> is changing a bit, any =" is changing to =\"

 

is there anyway of getting php to use this with out adding the \ in front of the quotation?

I got an script I wrote to help with updating my rss feed, since I do it manually.

But I have a problem, when I click submit the text in the textbox <textbox> is changing a bit, any =" is changing to =\"

 

is there anyway of getting php to use this with out adding the \ in front of the quotation?

 

 

when getting your from your form (example: $data = $_POST['data'];)  use htmlspecialchars() as like $data = htmlspecialchars($_POST['data']; 

Well, just to elaborate a bit:

 

PHP had this php.ini setting called "magic_quotes_gpc", which "magically quotes" GET, POST, and COOKIE data (hence, GPC).  It was to make using this data in external programs like MySQL more secure.  Turns out however, that it just causes problems.  Either you could turn it off, or use a function like this:

 

<?php
function real_stripslashes($string) {
    if (ini_get('magic_quotes_gpc') == true) {
        return stripslashes($string);
    }
    return $string;
}

I got an script I wrote to help with updating my rss feed, since I do it manually.

But I have a problem, when I click submit the text in the textbox <textbox> is changing a bit, any =" is changing to =\"

 

is there anyway of getting php to use this with out adding the \ in front of the quotation?

 

 

when getting your from your form (example: $data = $_POST['data'];)  use htmlspecialchars() as like $data = htmlspecialchars($_POST['data'];  

 

Thanks for this, it got rid of a lot of my AMATURE coding ... :)

 

Hi

 

I would personally use the stripslashes() function.

 

<?php
$str = "Submitted on \"PHPFreaks\" forum";
echo stripslashes($str);
?>

 

Hope this helps.

 

 

 

Tom

 

Also thanks to you, this fixed my \" issue! :)

 

Well, just to elaborate a bit:

 

PHP had this php.ini setting called "magic_quotes_gpc", which "magically quotes" GET, POST, and COOKIE data (hence, GPC).  It was to make using this data in external programs like MySQL more secure.  Turns out however, that it just causes problems.  Either you could turn it off, or use a function like this:

 

<?php
function real_stripslashes($string) {
    if (ini_get('magic_quotes_gpc') == true) {
        return stripslashes($string);
    }
    return $string;
}

The standard striplashes seems to do the trick, but if I pick up any problems I will try this!

Thanks as well!

The reason why just using stripslashes() is bad is because if your webhost just turns off magic_quotes_gpc,  you'll be killing any legitimate slashes in the string.  The function I posted makes sure magic_quotes_gpc is on before stripslash()ing.

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.