Manual of PHP

 
 
 

Web map

 
rim   rim
Frontarrow Ready of Codes PHParrow Ringlet to get all the variables for POST in PHP

 

Ringlet to get all the variables for POST in PHP To print E-mail
A very rapid way of receiving all the variables of a form, sent for post. By means of a generic trip of the array $_POST, in the language PHP.

We are going to see a very rapid way of receiving all the variables of a form, sent for post, in the language PHP. I make sure you that it is a small portion of code that will save you to write a heap of lines of code.

Who has not ever met in the tedious task of receiving a heap of information of a form, assigning one for one all the variables in PHP? That was done by lines like this one:


$nombre = $_POST ["name"];
$edad = $_POST ["age"];
$ciudad = $_POST ["city"];
....


If the form had 10 elements it would not be very heavy to write 10 code lines, but if there were 50 or 100 the thing would be much less agreeable. The code that we are going to see now will solve the life to us in these cases.

foreach ($_POST grasp $nombre_campo => $valor) {
   $asignacion = "\$". $nombre_campo. "= '". $valor. "';";
   eval ($asignacion);
}


It realizes a ringlet foreach that each of the elements is covering of the post. In every iteration, they are gaining access to all the elements of the post and one keeps in $ nombre_campo the name of the field got for the form and in $valor, the value that had got in the form.

Everything previous is deduced of the first line. In the following ones it consists in every iteration, each of the allocations that we should have written manually. Namely in the variable allocation we will keep a line of code PHP that realizes the declaration of the variable of form inside PHP and his initialization with the value that had been written.

In the following line, where the function is eval (), there is executed the judgment generated in the previous step. The function eval () of PHP executes the content of a chain of characters as if it was a judgment PHP. (We can see the papers of the function eval () on the PHP page http://es.php.net/manual/es/function.eval.php)

We hope that you should have been interested in this one minuscule, but useful, code PHP.

Miguel Angel Alvarez
http://www.desarrolloweb.com/articulos/1326.php?manual=6

 

 
Front
Chapters of the Manual of PHP
Introduction to PHP
Variables
My First Script PHP
Operators in PHP
Structures of Control
Functions in PHP
Code inclusion
Counterfoils (array)
Chains of Characters
Classes
Dates
Entry and Exit
Operations with Files
The language SQL and PHP
Connection with MySQL
Meetings
Forms with PHP
To practise in line
List of practices in line
FAQ
Frequent questions
Codes PHP
List of Codes PHP
Forums
Forums PHP
Other Manuals
Manuals of other languages
 
   
 
 
MySpaceScripts.info - Sitemap - Contact us - Sitemap - Contact us - Sitemap - Contact us

Li-Ion Battery for IBM , ferienhaus polen , Repliche di Orologi , grout sealing , Stag night Krakow , Used auto , hearing aids