I originally needed this in a PHP class that was pulling my data coming from MySQL. This function removes the slashes from varying input types of arrays, objects and strings so no matter what you input, you will get it back in the same format… minus the slashes, of course.

To modify for use in a class, remember to update the two internal calls to itself “stripslashesFull” with the proper class->function call or array(‘class’, ‘function’) inside of array_map().

/**
 * Remove slashes from strings, arrays and objects
 *
 * @param    mixed   input data
 * @return   mixed   cleaned input data
 */
function stripslashesFull($input)
{
	if (is_array($input)) {
		$input = array_map('stripslashesFull', $input);
	} elseif (is_object($input)) {
		$vars = get_object_vars($input);
		foreach ($vars as $k=>$v) {
			$input->{$k} = stripslashesFull($v);
		}
	} else {
		$input = stripslashes($input);
	}
	return $input;
}
0 0 votes
Article Rating
in PHP
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Nathan
11 years ago

Hi your function saved me a lot of time, so thank you!!! 🙂

Haider
Haider
10 years ago

Hi, I used it and it is working great. Thank You!

Really useful function. I am using it in my applications. This must be included in PHP releases. It is really good, quick and easy.