Destramic Posted May 9, 2010 Share Posted May 9, 2010 i'm trying to get strip/add slashes function working but its coming up with an error on this line...but im sure im doing the right thing...does anyone know where im going wrong please or even if this is possible $function = "add"; // or strip $value = {$function}slashes($value); thank you destramic Quote Link to comment https://forums.phpfreaks.com/topic/201177-variable-variables-function/ Share on other sites More sharing options...
ignace Posted May 9, 2010 Share Posted May 9, 2010 $function = 'add'; if (function_exists($function . 'slashes')) { $value = call_user_func($function . 'slashes', $value); } Quote Link to comment https://forums.phpfreaks.com/topic/201177-variable-variables-function/#findComment-1055485 Share on other sites More sharing options...
Destramic Posted May 9, 2010 Author Share Posted May 9, 2010 wow that was great...thank you! Quote Link to comment https://forums.phpfreaks.com/topic/201177-variable-variables-function/#findComment-1055490 Share on other sites More sharing options...
Destramic Posted May 9, 2010 Author Share Posted May 9, 2010 sorry im now having an error...i was firstly just setting $function as strip but when setting it in function argument as below im getting the error: Warning: Missing argument 2 for add_strip_slashes_deep() strange <?php function add_strip_slashes_deep($value, $function) { if (function_exists($function . "slashes")) { if (get_magic_quotes_gpc() && is_array($value)) { $value = array_map("add_strip_slashes_deep", $value); } else if (is_string($value)) { $value = call_user_func($function . 'slashes', $value); } } else { echo "An error has occurred.<br />\n"; } return $value; } // Example $array = array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar")); $array = add_strip_slashes_deep($array, "strip"); // Output print_r($array); ?> Quote Link to comment https://forums.phpfreaks.com/topic/201177-variable-variables-function/#findComment-1055543 Share on other sites More sharing options...
Alex Posted May 9, 2010 Share Posted May 9, 2010 You could replace: $value = array_map("add_strip_slashes_deep", $value); With: $value = array_map("add_strip_slashes_deep", $value, array_fill(0, sizeof($value), $function)); or just: foreach($value as &$element) { $element = add_strip_slashes_deep($element, $function); } Quote Link to comment https://forums.phpfreaks.com/topic/201177-variable-variables-function/#findComment-1055550 Share on other sites More sharing options...
Destramic Posted May 9, 2010 Author Share Posted May 9, 2010 i don't think that is the problem...its not noticing the argument $function when set to strip Quote Link to comment https://forums.phpfreaks.com/topic/201177-variable-variables-function/#findComment-1055553 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.