Destramic Posted January 1, 2007 Share Posted January 1, 2007 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]<?phpfunction 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? whyecho $b;?>[/code]thank you destramic Quote Link to comment https://forums.phpfreaks.com/topic/32481-addslashes-part-ii/ Share on other sites More sharing options...
dcro2 Posted January 1, 2007 Share Posted January 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/32481-addslashes-part-ii/#findComment-150898 Share on other sites More sharing options...
Destramic Posted January 1, 2007 Author Share Posted January 1, 2007 im just having problems getting the result with addedslashes without using print_r();as you can see if you run script and echo $b Quote Link to comment https://forums.phpfreaks.com/topic/32481-addslashes-part-ii/#findComment-150933 Share on other sites More sharing options...
corbin Posted January 1, 2007 Share Posted January 1, 2007 [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); Quote Link to comment https://forums.phpfreaks.com/topic/32481-addslashes-part-ii/#findComment-150935 Share on other sites More sharing options...
Destramic Posted January 2, 2007 Author Share Posted January 2, 2007 ok thanks for that :D destramic Quote Link to comment https://forums.phpfreaks.com/topic/32481-addslashes-part-ii/#findComment-151367 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.