When I sent articles to my database they enter find with apostrophes, but when I retrieve them from the database and have them sent to the browser to edit the text fields, they always return as the following:
\'
It seems MySQL is adding the slash so it doesn't confuse the apostrophe as the end or start of a command, but how do I go about stripping that slash when retrieving the results to my browser?
Apostrophe problem in results
Moderator: General Moderators
what doesprint?
Code: Select all
foreach ( array('magic_quotes_gpc', 'magic_quotes_runtime', 'magic_quotes_sybase') as $p ) {
echo $p, ': ', ini_get($p) ? 'On':'Off', "<br />\n";
}Can you change the server configuration and turn this nonsense off?http://de2.php.net/manual/en/ref.info.php#ini.magic-quotes-gpc wrote: magic_quotes_gpc boolean
Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
You can disable them through .htaccess:
Or use this code, provided to me by members of the DevNet, at the start of all of your files (in the form of a config.php of some sort):
It's better to support and deal with magic_quotes than to just turn them off (until PHP 6 ^_^).
Code: Select all
# As my lovely host that thinks magic_quotes is a good thing informed me...
php_flag magic_quotes_gpc offCode: Select all
// Strip slashes from all GPC data
if(get_magic_quotes_gpc())
{
function strip_gpc_slashes(&$array)
{
if(!is_array($array))
{
return;
}
foreach($array as $key => $val)
{
is_array($array[$key]) ? strip_gpc_slashes($array[$key]) : ($array[$key] = stripslashes($val));
}
}
$gpc = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST, &$_FILES);
strip_gpc_slashes($gpc);
}I can cause at this point I'm just testing it locally, but once I upload the site to a server I'm not sure. Haven't tried yet.volka wrote:Can you change the server configuration and turn this nonsense off?http://de2.php.net/manual/en/ref.info.php#ini.magic-quotes-gpc wrote: magic_quotes_gpc boolean
Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically.