note 47219 added to function.addslashes

From: Date: Sun, 07 Nov 2004 01:23:04 +0000
Subject: note 47219 added to function.addslashes
Groups: php.notes 
Request: Send a blank email to php-notes+get-80205@lists.php.net to get a copy of this message
Regarding the previous note using addslashes/stripslahes with regular expressions and databases it looks as if the purpose of these functions gets mixed. addslahes encodes data to be sent to a database or something similar. Here you need addslashes because you send commands to the database as command strings that contain data and thus you have to escape characters that are special in the command language like SQL. Therefore the use of addslahses on a regex does properly store the regex in the database. stripslashes does the opposite: it decodes an addslashes encoded string. However, retrieving data from a database works differently: it does not go through some string interpretation because you actually retrieve your binary data in your variables. In other words: the data stored in your variable is the unmodified binary data that your database returned. You do not run stripslahes on data returned from a database. That way, the regexs are retrieved correctly, too. This is different from other data exchange like urlencoded strings that you exchange with your browser. Here the data channel uses the same encodings in both directions: therefore you have to encode data to be sent and you have to decode data received. ---- Manual Page -- http://www.php.net/manual/en/function.addslashes.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47219 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47219&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47219&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47219&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47219&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47219&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47219&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47219&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80205) next »