Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/201177-variable-variables-function/
Share on other sites

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

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

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.