note 46657 added to function.addslashes

From: Date: Tue, 19 Oct 2004 15:08:43 +0000
Subject: note 46657 added to function.addslashes
Groups: php.notes 
Request: Send a blank email to php-notes+get-78762@lists.php.net to get a copy of this message
Be very careful when using addslashes and stripslashes in combination with regular expression that will be stored in a MySQL database. Especially when the regular expression contain escape characters! To store a regular expression with escape characters in a MySQL database you use addslashes. For example: $l_reg_exp = addslashes( “[\x00-\x1F]” ); After this the variable $l_reg_exp will contain: [\\x00-\\x1F]. When you store this regular expression in a MySQL database, the regular expression in the database becomes [\x00-\x1F]. When you retrieve the regular expression from the MySQL database and apply the PHP function stripslashes(), the single backslashes will be gone! The regular expression will become [x00-x1F] and your regular expression might not work! ---- Manual Page -- http://www.php.net/manual/en/function.addslashes.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46657 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46657&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46657&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46657&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46657&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46657&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46657&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46657&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78762) next »