note 27226 deleted from function.addslashes by philip
| From: | philip@php.net | Date: | Tue, 20 Jul 2004 17:11:54 +0000 |
| Subject: | note 27226 deleted from function.addslashes by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73705@lists.php.net to get a copy of this message | ||
Note Submitter: thelogrus@yahoo.se
----
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