Strip slashes from arrays, objects and strings in PHP

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 vote
Article Rating
in PHP
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
7 years ago

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

6 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.