Page 1 of 1
Apostrophe problem in results
Posted: Sat Aug 04, 2007 12:12 am
by trassalg
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?
Posted: Sat Aug 04, 2007 12:38 am
by volka
what does
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";
}
print?
Posted: Sat Aug 04, 2007 12:55 am
by trassalg
magic_quotes_gpc: On
magic_quotes_runtime: Off
magic_quotes_sybase: Off
Posted: Sat Aug 04, 2007 1:21 am
by volka
Can you change the server configuration and turn this nonsense off?
Posted: Sat Aug 04, 2007 7:52 am
by superdezign
You can disable them through .htaccess:
Code: Select all
# As my lovely host that thinks magic_quotes is a good thing informed me...
php_flag magic_quotes_gpc off
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):
Code: 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);
}
It's better to support and deal with magic_quotes than to just turn them off (until PHP 6 ^_^).
Posted: Sat Aug 04, 2007 2:53 pm
by trassalg
volka wrote:Can you change the server configuration and turn this nonsense off?
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.