note 95775 added to function.stripslashes

From: Date: Thu, 21 Jan 2010 13:01:19 +0000
Subject: note 95775 added to function.stripslashes
Groups: php.notes 
Request: Send a blank email to php-notes+get-165162@lists.php.net to get a copy of this message
Another way to strip slashes only if necessary, independent of magic_quotes_gpc by comparing the count of (possibly) escaped characters and original characters. <?php function smartstripslashes($str) { $cd1 = substr_count($str, "\""); $cd2 = substr_count($str, "\\\""); $cs1 = substr_count($str, "'"); $cs2 = substr_count($str, "\\'"); $tmp = strtr($str, array("\\\"" => "", "\\'" => "")); $cb1 = substr_count($tmp, "\\"); $cb2 = substr_count($tmp, "\\\\"); if ($cd1 == $cd2 && $cs1 == $cs2 && $cb1 == 2 * $cb2) { return strtr($str, array("\\\"" => "\"", "\\'" => "'", "\\\\" => "\\")); } return $str; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 194.95.108.67 ---- Manual Page -- http://www.php.net/manual/en/function.stripslashes.php Edit -- https://master.php.net/note/edit/95775 Del: integrated -- https://master.php.net/note/delete/95775/integrated Del: useless -- https://master.php.net/note/delete/95775/useless Del: bad code -- https://master.php.net/note/delete/95775/bad+code Del: spam -- https://master.php.net/note/delete/95775/spam Del: non-english -- https://master.php.net/note/delete/95775/non-english Del: in docs -- https://master.php.net/note/delete/95775/in+docs Del: other reasons-- https://master.php.net/note/delete/95775 Reject -- https://master.php.net/note/reject/95775 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165162) next »