Jump to content

Question On Backslashes


HowdeeDoodee

Recommended Posts

I am building a self-tutorial and have hit a snag on the  matter of backslashes.

 

With these settings in php.ini, it makes no difference in how these settings are set.

The backslashes are not stripped out of words where backslashes appear no matter how the magic quotes are set in php.ini.

 

magic_quotes_gpc = On

magic_quotes_runtime = On

magic_quotes_sybase = On

 

OR

 

magic_quotes_gpc = Off

magic_quotes_runtime = Off

magic_quotes_sybase = Off

 

Makes no difference. Can someone explain why the backslashes appear no matter what the settings in php.ini might be?

 

Here is sample code...

 

$SeeAlso = "It is the Lord\'s day of 1000\'s";
echo '<br>';
echo $SeeAlso;
echo '<br>';

echo get_magic_quotes_gpc();


function quote_smart($SeeAlso)
{
// Stripslashes
//get_magic_quotes_gpc Returns 0 if magic quotes gpc are off, 1 otherwise.
if (get_magic_quotes_gpc())
{
$SeeAlso = stripslashes($SeeAlso);
}
// Quote if not a number or a numeric string
//mysql_real_escape_string — Escapes special characters in a string
//for use in a SQL statement
if (!is_numeric($SeeAlso))
{
$SeeAlso = "'" . mysql_real_escape_string($SeeAlso) . "'";
}
return $SeeAlso;
}
echo '<br>';
echo '<br>';
echo $SeeAlso;
echo '<br>';
echo '<br>';

 

Thank you in advance for any help.

Link to comment
https://forums.phpfreaks.com/topic/167103-question-on-backslashes/
Share on other sites

Firstly you don't use your function anywhere in that code.

 

If you did it would throw an error as you can only use mysql_real_escape_string() when connected to a db.

 

Also magic_quote_gpc;

 

Affects HTTP Request data (GET, POST, and COOKIE)

 

It won't affect your string unless the string is sent via a HTTP request

 

magic_quotes_runtime;

 

If enabled, most functions that return data from an external source, including databases and text files, will have quotes escaped with a backslash.

 

This won't affect a string that you have assigned to a variable

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.