PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > PHP "preg_replace"
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
PHP "preg_replace"

Réponse
 
LinkBack Outils de la discussion
Vieux 17/09/2007, 17h41   #1
Chaim Chaikin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut PHP "preg_replace"

Hello,



I am a beginner in PHP. I need with the function preg_replace.

I am trying to remove the backslashes ( \ ) from a string that is submitted
by the user.

It is submitted in a form but it adds \ before the quotation marks ( " ).

Will this change if I use the GET method instead of POST.

If not can you please tell me how to use preg_replace to remove the
backslashes.



Thank You,

Chaim Chaikin

Novice PHP programmer

Hotwire Band Website Administrator

http://hotwire.totalh.com


  Réponse avec citation
Vieux 17/09/2007, 19h00   #2
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP "preg_replace"

Chaim Chaikin wrote:
> Hello,
>
>
>
> I am a beginner in PHP. I need with the function preg_replace.
>
> I am trying to remove the backslashes ( \ ) from a string that is submitted
> by the user.
>
> It is submitted in a form but it adds \ before the quotation marks ( " ).
>
> Will this change if I use the GET method instead of POST.
>
> If not can you please tell me how to use preg_replace to remove the
> backslashes.
>

Don't, use stripslashes() instead.

http://us.php.net/stripslashes

Here is a nice little hack that I use.

<plaintext><?php

print_r($_REQUEST);

function stripInput(&$ar) {
$ar = stripslashes($ar);
}
if ( get_magic_quotes_gpc() ) {
array_walk_recursive($_REQUEST, 'stripInput');
array_walk_recursive($_POST, 'stripInput');
array_walk_recursive($_GET, 'stripInput');
}

print_r($_REQUEST);

?>

you should see the difference
--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
  Réponse avec citation
Vieux 17/09/2007, 23h00   #3
Arpad Ray
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP "preg_replace"

Jim Lucas wrote:
> Here is a nice little hack that I use.
>


"Little hack" it is, "nice" it isn't.
Ideally just turn off magic_quotes_gpc - you can do so in php.ini, or
perhaps your web server configuration files (httpd.conf, .htaccess etc.).

If you don't have access to any of the above then install the latest
version of PHP_Compat (http://pear.php.net/package/PHP_Compat) and
include 'PHP/Compat/Environment/magic_quotes_gpc_off.php'. Reversing the
effects of magic_quotes_gpc at runtime is far from trivial, there's lots
of potential for subtle bugs, let alone completely forgetting about
$_.

If you're unable to install PHP_Compat, you can grab the relevant files
from CVS:
http://cvs.php.net/viewvc.cgi/pear/P....3&view=markup
http://cvs.php.net/viewvc.cgi/pear/P....7&view=markup

Arpad
  Réponse avec citation
Vieux 18/09/2007, 15h26   #4
Al
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP "preg_replace"

Just use stripslashes() on your submitted data and forget about testing for
magic_quotes. It's good practice anyhow. \" is not legit text regardless.



haim Chaikin wrote:
> Hello,
>
>
>
> I am a beginner in PHP. I need with the function preg_replace.
>
> I am trying to remove the backslashes ( \ ) from a string that is submitted
> by the user.
>
> It is submitted in a form but it adds \ before the quotation marks ( " ).
>
> Will this change if I use the GET method instead of POST.
>
> If not can you please tell me how to use preg_replace to remove the
> backslashes.
>
>
>
> Thank You,
>
> Chaim Chaikin
>
> Novice PHP programmer
>
> Hotwire Band Website Administrator
>
> http://hotwire.totalh.com
>
>

  Réponse avec citation
Vieux 18/09/2007, 23h37   #5
Arpad Ray
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: PHP "preg_replace"

Apologies if you already received this message, I tried to send it
earlier from my webmail but it doesn't seem to have worked.

Al wrote:
> Just use stripslashes() on your submitted data and forget about
> testing for magic_quotes. It's good practice anyhow. \" is not legit
> text regardless.
>


Using stripslashes() on all submitted data is most certainly *not* good
practice. If magic_quotes_gpc is later turned off or you're using one of
the versions of PHP with buggy magic_quotes_gpc support then you can
easily lose data. Reversing the effects of magic_quotes_gpc is far from
trivial, there's lots of potential for subtle bugs, let alone completely
forgetting about $_.

See my earlier reply for a real solution.

Arpad
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h51.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10288 seconds with 13 queries