Re: DataObjects setFrom and DB:quote woes
| From: | Aidan Lister | Date: | Mon, 05 Apr 2004 06:11:00 +0000 |
| Subject: | Re: DataObjects setFrom and DB:quote woes | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11619@lists.php.net to get a copy of this message | ||
Not the fastest code ever, I suggest:
if (get_magic_quotes_gpc()) {
array_map($_GET, 'stripslashes');
array_map($_POST, 'stripslashes');
array_map($_COOKIE, 'stripslashes');
}
"Norbert Mocsnik" <pear-general@mocsnik.hu> wrote in message
news:4070B1C8.4080602@mocsnik.hu...
> Jacob Singh wrote:
> > 2. quote();
> >
> > This one is really pissing me off. When I submit a text field,
DataObjects
> > insists on putting tons of extra backslashes in. Every time I submit I
get a
> > few new backslashes, they seem to grow exponetially.
>
> I suspect the magic_quotes are on in your php.ini. If you are not able to
edit php.ini directly, try to use the following code snippet at the top of
your scripts, taken from the PHP manual:
>
> // *********************************************
> // remove magic quotes
> function no_magic_quotes_gpc(&$var)
> {
> if (is_string($var)) {
> $var = stripslashes($var);
> } elseif (is_array($var)) {
> foreach ($var as $key => $value) {
> no_magic_quotes_gpc($var[$key]);
> }
> } elseif (is_object($var)) {
> foreach (get_object_vars($var) as $key => $value) {
> no_magic_quotes_gpc($var->$key);
> }
> }
> }
>
> if (get_magic_quotes_gpc()) {
> no_magic_quotes_gpc($_GET);
> no_magic_quotes_gpc($_POST);
> no_magic_quotes_gpc($_COOKIE);
> }
>
> My experiences show that you won't have any problems with quotes when
using PEAR if:
> - you turn off magic quotes in php.ini or use the above code snippet
> - when displaying contents from the database to html forms (<input
type=text> etc..), display values using nl2br(htmlspecialchars($value))
instead of putting $value directly into <input type=text value="$value">
>
> Regards,
> Norbert