PHP访问的所有$ _ POST []变量到一个数组? [英] PHP access all $_POST[] variables into an array?

查看:261
本文介绍了PHP访问的所有$ _ POST []变量到一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何捕捉在 $ _ POST 变量的所有领域?
到一个数组?

how to capture all fields in the $_POST VARIABLE? into an array?

$email = $_POST;
$emails = array_keys($email);
foreach($emails as $email) {
        echo '$' . nl2br($email);
}
$emailadd = new email_save;
$emailadd->insert_email_into_database("POST VARIABLES GO HERE)

我试图做一个邮件列表,姓名和电子邮件地址,
我怎么捕获贴在哪里可以进行正常访问一样的所有变量
$ _ POST [电子邮件] 到一个数组,所以我可以在我的功能,将它们添加到参数呢?

I'm trying to make an email list, name and email address, how do I capture all the variables that where posted that can normal be accessed like $_POST['email'] into an array so i can add them to the arguments in my functions?

我的表单字段有5个领域。
该方法是POST。

My form field has 5 fields. The method is POST.

代替写信

$email = mysql_real_escape_string($_POST['email']);
$firstname = mysql_real_escape_string($_POST['firstname']);

我试图访​​问$ _POST []数组中的所有值;
这样我就可以节省时间,让贴变量
并添加功能,这些变量如 mysql_real_escape_string();

其他安全措施会想通了。

Other security measures will be figured out.

我希望能够到阵列的reffrence增加了一项功能,我可以将它们添加到数据库中。

I want to be able to add a reffrence of the array to a function so I can add them to the database.

推荐答案

如果您想从提交的表单捕捉列表,然后使用数组语法把戏,而不是列举输入字段名:

If you want to capture a list from a POSTed form, then use the array syntax trick instead of enumerated input field names:

<input type="email" name="emails[]">
<input type="email" name="emails[]">
<input type="email" name="emails[]">

这样,你需要PHP中没有猜测,因为电子邮件[] 成为一个数组隐含那么:

This way you need no guessing in PHP, because emails[] becomes an array implicitely then:

print_r($_POST["emails"]);
foreach ($_POST["emails"] as $email) {

有关数据库逃脱只需使用:

For database-escaping just use:

$db_emails = array_map("mysql_real_escape_string", $_POST["emails"]);
// that's an array too

这篇关于PHP访问的所有$ _ POST []变量到一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆