note 27226 added to function.addslashes
| From: | thelogrus at yahoo dot se | Date: | Thu, 28 Nov 2002 02:38:09 +0000 |
| Subject: | note 27226 added to function.addslashes | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40059@lists.php.net to get a copy of this message | ||
Hello...
Well I came upon a slightly annoying thing when using
addslashes to fix the data to be stored into mysql db.
input looking like:
Sir'Weaser
Now with addslashes it gets turned into:
Sir\'Weaser
Now I store it.
Then I of course wish to recover it and print it when someone
wants to see Sir'Weaser's info.
Now the output would look:
Name: Sir\'Weaser
Annyoing eh? So I do this:
function rslash($RF){
$RF2=$RF;
foreach($RF as $key =>$v){
if(is_string($v)){
$RF2[$key]=stripslashes($RF[$key]);
}
}
return $RF2;
}
$sql="SELECT * FROM Users";
$rs_r=mysql_query($sql);
$rs=mysql_fetch_array($rs_r);
$rs=rslash($rs);
print $rs['UserName'];
and it looks as it should that is:
Name: Sir'Weaser.
---
It helped me once i figured it out, hope it helps someone else.
(Now someone will point out to me a way to do this that is much more efficent, it usualy goes that
way :-) )
/C
--
http://www.php.net/manual/en/function.addslashes.php
http://master.php.net/manage/user-notes.php?action=edit+27226
http://master.php.net/manage/user-notes.php?action=delete+27226
http://master.php.net/manage/user-notes.php?action=reject+27226