Jump to content

addslashes part II


Destramic

Recommended Posts

im having trouble with this addslashes wrapper....basically if i addslashes to a string/array all commas will have a slash infront of it. So when i call the variable after running it through the function it should have a slash if needed. but when variable is called it has no slash...you can only see the slash when using print_r();

it will work this way...but i should have to do it like that?[code]$b = add_slashes($b);[/code]

can anyone help please? (here is the script below..)

[code]
<?php

function add_slashes($value)
{
// Check if string exists
if (is_string($value))
{
return addslashes($value);
}
elseif (is_array($value))
{
return array_map('add_slashes', $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( add_slashes($a));
$b = "This's an string's";
print_r( add_slashes($b));

// If i was to echo $b it would echo This's an string's without slashes? why
echo $b;

?>
[/code]

thank you destramic
Link to comment
Share on other sites

I'm not sure you understand what addslashes() does...

[quote]Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash (\) and NUL (the NULL byte).[/quote]

Or maybe I don't understand what you're doing with commas.
Link to comment
Share on other sites

[code]
Array ( [0] => [1] => This\'s an string\'s [2] => This\'s an string\'s [3] => Array ( [0] => This\'s an string\'s [1] => Array ( [0] => This\'s an string\'s [1] => This\'s an string\'s ) ) [4] => This\'s an string\'s [5] => This\'s an string\'s ) This\'s an string\'sThis's an string's
[/code]
That is what it puts out for me...

The reason $b is echoing This's a string's is because b is not updated...  You would need to call $b = add_slashes($b);
Link to comment
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.