Destramic Posted November 14, 2006 Share Posted November 14, 2006 i have a function which will stripslashes in a string but doesnt seem to be working when i stripslashes on my forms values....can anyone help? (dont think it works at all)[code]function strip_slashes($value){ // Check if Magic Quotes is enabled if (get_magic_quotes_gpc()) { // Check if string exists if (is_string($value)) { return stripslashes($value); } elseif (is_array($value)) { return array_map('strip_slashes', $value); } } else { return $value; }}[/code]destramic Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/ Share on other sites More sharing options...
The Little Guy Posted November 14, 2006 Share Posted November 14, 2006 Try this:[code]function strip_slashes($value){ // Check if Magic Quotes is enabled if (get_magic_quotes_gpc()) { // Check if string exists if (is_string($value)) { $result = stripslashes($value); } elseif (is_array($value)) { $result = array_map('strip_slashes', $value); } } else { $reslult = $value; } return $result;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-124595 Share on other sites More sharing options...
Destramic Posted November 14, 2006 Author Share Posted November 14, 2006 sorry still no luck =/ Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-124714 Share on other sites More sharing options...
The Little Guy Posted November 14, 2006 Share Posted November 14, 2006 This works for me:[code]<?phpfunction strip_slashes($value){ // Check if Magic Quotes is enabled if (get_magic_quotes_gpc()) { // Check if string exists if (is_string($value)) { return stripslashes($value); } elseif (is_array($value)) { return array_map('strip_slashes', $value); } } else { return $value; }}echo strip_slashes("This\'s an string\'s");?>[/code]Preview: http://d-top.org/webdeveloper/test.php Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-124725 Share on other sites More sharing options...
Destramic Posted November 14, 2006 Author Share Posted November 14, 2006 try this:when on site type: This\'s an string\'s in name field and see what happens...(funtion doesnt work)http://82.47.43.58/error.php?error=unknown Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-124755 Share on other sites More sharing options...
Destramic Posted November 15, 2006 Author Share Posted November 15, 2006 im thinking maybe my.htaccess file isnt working as i have php_value magic_quotes_gpc onhelp? Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-125058 Share on other sites More sharing options...
The Little Guy Posted November 15, 2006 Share Posted November 15, 2006 [code]<?phpfunction strip_slashes($value){ // Check if string exists if (is_string($value)) { return stripslashes($value); } elseif (is_array($value)) { return array_map('strip_slashes', $value); } else { return stripslashes($value); }}echo strip_slashes("This\'s an string\'s");?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-125078 Share on other sites More sharing options...
Destramic Posted November 18, 2006 Author Share Posted November 18, 2006 the function seems to work on strings...but arrays i cant get it to work on...help? Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-126633 Share on other sites More sharing options...
Destramic Posted November 19, 2006 Author Share Posted November 19, 2006 anyone know how i can stripslashes on array? Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-127007 Share on other sites More sharing options...
sasa Posted November 19, 2006 Share Posted November 19, 2006 try[code]<?phpfunction strip_slashes($value){ if (is_array($value)) return array_map('strip_slashes', $value); return get_magic_quotes_gpc() ? stripslashes($value) : $value;}$a = array(0,"This\'s an string\'s","This\'s an string\'s",array("This\'s an string\'s",array("This\'s an string\'s","This\'s an string\'s")),"This\'s an string\'s\\","This\'s an string\'s");print_r( strip_slashes($a));$b = "This\'s an string\'s";print_r( strip_slashes($b));?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-127020 Share on other sites More sharing options...
Destramic Posted November 19, 2006 Author Share Posted November 19, 2006 thank you so much that works fine...only problem i have now is when i use it on my form when i post this:This\'s an string\'s and then submit it will then do something like this in the input box:This\\\'s an string\\\'sis there a simple way of making this work?see for yourself:http://82.47.18.28/error.php?error=404 Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-127024 Share on other sites More sharing options...
kenrbnsn Posted November 19, 2006 Share Posted November 19, 2006 Do not put in backslashes manually when entering data, if you do, PHP will escape them with backslashes. Use the stripslashes function when you display the data.Please post the code you're using to display the data.Ken Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-127036 Share on other sites More sharing options...
Destramic Posted November 20, 2006 Author Share Posted November 20, 2006 ok...well i though the best way to strip slashes is before it is added to the database....but you think i should do it when i am querying the results?thanks destramic Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-127537 Share on other sites More sharing options...
Destramic Posted November 21, 2006 Author Share Posted November 21, 2006 i think stripslashes should be done before data is added to the database...now we've got the function to work....how do i get it work on input boxes before going to mysql database...as ive said if i type: This\'s an string\'son submit in the input field it will show: This\\\'s an string\\\'s Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-127997 Share on other sites More sharing options...
Destramic Posted November 22, 2006 Author Share Posted November 22, 2006 the code below will work for strings and arrays...but doesnt seem to work for $_POST and $_GET etc...anyone figure out why ?[code]<?phpfunction strip_slashes($value){ // Check if Magic Quotes is enabled if (get_magic_quotes_gpc()) { // Check if string exists if (is_string($value)) { return stripslashes($value); } elseif (is_array($value)) { return array_map('strip_slashes', $value); } }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-128793 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.