PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.comp.lang.php > Perform the same action(s) on a variable number of POST variables
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Perform the same action(s) on a variable number of POST variables

Réponse
 
LinkBack Outils de la discussion
Vieux 14/06/2007, 22h25   #1
joboils@hotmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Perform the same action(s) on a variable number of POST variables

Hope some of the gurus around here can me stop feeling stupid.
Is there some way to have the same actions (like, say, STR_REPLACE(),
TRIM() or STRTOUPPER(), and stuff like that) operate on all the
variables passed by POST from a range of web forms without writing
these actions specifically for each form's variables?
The number, and names, of the variables passed by POST wil vary with
each form.
I suppose I'm looking for a script which I can make as an include()
which I can call to do the business, irrespective of the names and
numbers of the variables passed.
Rather than re-inventing the wheel, does anyone know if there is an
existing script which will do that?
TIA.
  Réponse avec citation
Vieux 14/06/2007, 22h42   #2
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Perform the same action(s) on a variable number of POST variables

..oO(joboils@hotmail.com)

>Hope some of the gurus around here can me stop feeling stupid.
>Is there some way to have the same actions (like, say, STR_REPLACE(),
>TRIM() or STRTOUPPER(), and stuff like that) operate on all the
>variables passed by POST from a range of web forms without writing
>these actions specifically for each form's variables?


foreach?

Micha
  Réponse avec citation
Vieux 15/06/2007, 04h38   #3
Gleep
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Perform the same action(s) on a variable number of POST variables

On Thu, 14 Jun 2007 23:42:36 +0200, Michael Fesser <netizen@gmx.de> wrote:

>.oO(joboils@hotmail.com)
>
>>Hope some of the gurus around here can me stop feeling stupid.
>>Is there some way to have the same actions (like, say, STR_REPLACE(),
>>TRIM() or STRTOUPPER(), and stuff like that) operate on all the
>>variables passed by POST from a range of web forms without writing
>>these actions specifically for each form's variables?

>
>foreach?
>
>Micha



yup, treat $_POST as you would an array because it is an array

example
foreach($_POST as $key => $item)
{
$$key = trim($_POST[$key]);
}

key is a variable variable

it would be the equivalent of this

$apple = $_POST['apple'];
$orange = $_POST['orange'];
$pear = $_POST['pear'];

etc..

with the loop above you don't have to go thru the process of calling each one out
it's done throu the loop - hope that makes sense


  Réponse avec citation
Vieux 15/06/2007, 09h03   #4
joboils@hotmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Perform the same action(s) on a variable number of POST variables

On Thu, 14 Jun 2007 20:38:10 -0700, Gleep <Gleep@Gleep.com> wrote:

>On Thu, 14 Jun 2007 23:42:36 +0200, Michael Fesser <netizen@gmx.de> wrote:
>
>>.oO(joboils@hotmail.com)
>>
>>>Hope some of the gurus around here can me stop feeling stupid.
>>>Is there some way to have the same actions (like, say, STR_REPLACE(),
>>>TRIM() or STRTOUPPER(), and stuff like that) operate on all the
>>>variables passed by POST from a range of web forms without writing
>>>these actions specifically for each form's variables?

>>
>>foreach?
>>
>>Micha

>
>
>yup, treat $_POST as you would an array because it is an array
>
>example
>foreach($_POST as $key => $item)
>{
>$$key = trim($_POST[$key]);
>}
>
>key is a variable variable
>
>it would be the equivalent of this
>
>$apple = $_POST['apple'];
>$orange = $_POST['orange'];
>$pear = $_POST['pear'];
>
>etc..
>
>with the loop above you don't have to go thru the process of calling each one out
>it's done throu the loop - hope that makes sense
>


Thank you. I've never worked with foreach (Shock! Horror!) so it'll
be interesting to see how I get along with it.
  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 12h55.


É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,10321 seconds with 12 queries