WordPress at a glance

add_magic_quotes() WP 0.71

Escape ', ", \ symbols in the elements of the array. Works with multidimensional arrays too.

This is a recursive function that works based on the addslashes() PHP function. Walks the array and escapes the values of its elements.

This is almost a copy of the wp_slash() function. The difference is that wp_slash() can process strings not only arrays.

No Hooks.

Return

Array. Sanitized $array.

Usage

add_magic_quotes( $array );
$array(array) (required)
Array to walk while sanitizing contents.

Examples

#1 Function operation example:

$array = array(
	"single quote - '",
	array('a nested array, with double quotes - "'),
	'slash - \ text'
);

$new_array = add_magic_quotes( $array );

print_r( $new_array );

Get this result:

Array
(
	[0] => single quote - \'
	[1] => Array
		(
			[0] => a nested array, with double quotes - \"
		)

	[2] => slash - \\ text
)

Code of add_magic_quotes: wp-includes/functions.php VER 4.9.8

<?php
function add_magic_quotes( $array ) {
	foreach ( (array) $array as $k => $v ) {
		if ( is_array( $v ) ) {
			$array[$k] = add_magic_quotes( $v );
		} else {
			$array[$k] = addslashes( $v );
		}
	}
	return $array;
}

Related Functions

From category: Formatting

No comments
    Hello, !     Log In . Register