获取所有以特定文本开头的$ _POST变量 [英] Get all $_POST variables starting with certain text
本文介绍了获取所有以特定文本开头的$ _POST变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个html表单,其中有一个部分会生成带有随机名称的输入.
I have an html form with a section that generates inputs with random names.
每个输入名称的开头都是文本"book",结尾是随机文本.
Each input name is generated with the text "book" at the beginning and random text at the end.
<input type="text" name="book_4552f" />
<input type="text" name="book_3507p" />
<input type="text" name="book_8031b" />
如何使用PHP获取以文本"book"开头的所有$ _POST变量?
How do I use PHP to get all $_POST variables which start with the text "book"?
推荐答案
以下内容使用 strpos()进行检查POST字符串以book_
The following uses strpos() to check that the POST string begins with book_
foreach($_POST as $key => $value) {
if (strpos($key, 'book_') === 0) {
// value starts with book_
}
}
这篇关于获取所有以特定文本开头的$ _POST变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文