note 59842 deleted from function.array-map by philip

From: Date: Thu, 22 Feb 2007 02:00:18 +0000
Subject: note 59842 deleted from function.array-map by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123689@lists.php.net to get a copy of this message
Note Submitter: jakob dot buchgraber at gmail dot com ---- This function escapes an array or string. The function uses addslashes for escaping the data, but if you work with i.e. MySQL you should use mysqli_real_escape_string() instead. <?php function escapeString($stringOrArray) { if (is_array($stringOrArray)) return array_map('escapeString',$stringOrArray); else { $stringOrArray = addslashes($stringOrArray); return $stringOrArray; } } $array = array('"""\\\$',"Peter's here"); $string = 'Hello I am "Mr XYZ"'; $array = escapeString($array); $string = escapeString($string); echo '<pre>'; print_r($array); echo '</pre>'; echo $string; /************The Output******************* Array ( [0] => \"\"\"\\\\$ [1] => Peter\'s here ) Hello I am \"Mr XYZ\" *************The Output******************/ ?>

« previous php.notes (#123689) next »