Jump to content

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/27247-stripslashes-function/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-124595
Share on other sites

This works for me:
[code]<?php

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;
}
}

echo strip_slashes("This\'s an string\'s");
?>[/code]

Preview: http://d-top.org/webdeveloper/test.php
Link to comment
https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-124725
Share on other sites

[code]<?php

function 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]
Link to comment
https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-125078
Share on other sites

try[code]<?php
function 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]
Link to comment
https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-127020
Share on other sites

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\\\'s

is there a simple way of making this work?

see for yourself:
http://82.47.18.28/error.php?error=404
Link to comment
https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-127024
Share on other sites

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\'s
on submit in the input field it will show: This\\\'s an string\\\'s
Link to comment
https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-127997
Share on other sites

the code below will work for strings and arrays...but doesnt seem to work for $_POST and $_GET etc...anyone figure out why ?

[code]
<?php

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);
}
}
}

?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/27247-stripslashes-function/#findComment-128793
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.