|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
..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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|