PHP控件数组语法与HTML标准 [英] PHP control array syntax vs HTML standard

查看:82
本文介绍了PHP控件数组语法与HTML标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP允许表单中的控件数组,例如这是一个计数器编辑脚本


echo"< input name = \" counterdelname [] \"键入= \" hidden\" value = \"" ;;


echo"< input name = \" countername [] \" type = \" hidden \"

value = \""。$ namestr。" \">";


echo"< input name = \" newvalue [] \" size =" .VALUEWIDTH。"

value = \""。$ valuestr。" \">" ;;


echo"< input name = \" delcounter ["。$ namestr。"] \" type = \" checkbox \">" ;;


结果网页可能看起来像这样,部分:


< td>< font face =" arial,helvetica" size = 2>< input

name =" delcounter [www.mysite.co.nz:]" type =" checkbox">< / font>< / td>

< tr>< td>< font face =" arial,helvetica" size = 2>< input name =" countername []"

type =" hidden"

value =" www.mysite.co.nz: /20040313/index.shtml"> www.mysite.co.nz:/20040313

/index.shtml</font></td>


PHP中的控件数组在处理表单时提供了显着的优势>
输入,其中有相同元素的可变数量的集合

在页面下多次重复以允许一组记录的

相同的数据要编辑的字段。表单元素在

处理脚本中作为一个数组接收,可以在

直接进行循环处理。


根据HTML 4.0标准,Input元素的名称应该遵循以下约定:


NAME标记必须以字母开头([ A-Za-z])并且可以跟随

任意数量的字母,数字([0-9]),连字符( - ),下划线(_) ,

冒号(:)和句号(。)。"


我什么也看不见关于方括号,它们是PHP数组语法的一部分,但是它们似乎被接受了,而且似乎PHP似乎是
能够将它接收到的所有元素转换为提交数组

表格到处理脚本。 CGI

约定或HTML中是否有允许这种语法的内容?

PHP allows control arrays in forms e.g. this is a counter editing script

echo "<input name=\"counterdelname[]\" type=\"hidden\" value=\"";

echo "<input name=\"countername[]\" type=\"hidden\"
value=\"".$namestr."\">";

echo "<input name=\"newvalue[]\" size=".VALUEWIDTH."
value=\"".$valuestr."\">";

echo "<input name=\"delcounter[".$namestr."]\" type=\"checkbox\">";

The resultant web page might look something like this, in part:

<td><font face="arial,helvetica" size=2><input
name="delcounter[www.mysite.co.nz:]" type="checkbox"></font></td>
<tr><td><font face="arial,helvetica" size=2><input name="countername[]"
type="hidden"
value="www.mysite.co.nz:/20040313/index.shtml">www.mysite.co.nz:/20040313
/index.shtml</font></td>

Control arrays in PHP offer significant advantages in processing form
input where there are a variable number of sets of the same elements
repeated multiple times down the page to allow a set of records of the
same data fields to be edited. The form elements are received back in the
processing script as an array which can be dealt with in a
straightforward for loop.

According to HTML 4.0 standards, the name of an Input element should
follow these conventions:

"NAME tokens must begin with a letter ([A-Za-z]) and may be followed by
any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), and periods (".")."

I don''t see anything there about the square brackets which are part of
the PHP array syntax, but they seem to be accepted and PHP seems to be
able to turn all the elements it receives into an array on the submission
of the form to the processing script. Is there something in the CGI
conventions or HTML that it does permit this syntax?

推荐答案

namestr。" \\ \\">" ;;


echo"< input name = \" newvalue [] \" size =" .VALUEWIDTH。"

value = \""。
namestr."\">";

echo "<input name=\"newvalue[]\" size=".VALUEWIDTH."
value=\"".


valuestr。" \">" ;;


echo"< input name = \" delcounter ["。
valuestr."\">";

echo "<input name=\"delcounter[".


namestr。"] \" type = \" checkbox \">" ;;


结果网页可能看起来像这样,部分:


< td>< font face =" arial,helvetica" size = 2>< input

name =" delcounter [www.mysite.co.nz:]" type =" checkbox">< / font>< / td>

< tr>< td>< font face =" arial,helvetica" size = 2>< input name =" countername []"

type =" hidden"

value =" www.mysite.co.nz: /20040313/index.shtml"> www.mysite.co.nz:/20040313

/index.shtml</font></td>


PHP中的控件数组在处理表单时提供了显着的优势>
输入,其中有相同元素的可变数量的集合

在页面下多次重复以允许一组记录的

相同的数据要编辑的字段。表单元素在

处理脚本中作为一个数组接收,可以在

直接进行循环处理。


根据HTML 4.0标准,Input元素的名称应该遵循以下约定:


NAME标记必须以字母开头([ A-Za-z])并且可以跟随

任意数量的字母,数字([0-9]),连字符( - ),下划线(_) ,

冒号(:)和句号(。)。"


我什么也看不见关于方括号,它们是PHP数组语法的一部分,但是它们似乎被接受了,而且似乎PHP似乎是
能够将它接收到的所有元素转换为提交数组

表格到处理脚本。 CGI

约定或HTML中是否有允许这种语法的内容?
namestr."]\" type=\"checkbox\">";

The resultant web page might look something like this, in part:

<td><font face="arial,helvetica" size=2><input
name="delcounter[www.mysite.co.nz:]" type="checkbox"></font></td>
<tr><td><font face="arial,helvetica" size=2><input name="countername[]"
type="hidden"
value="www.mysite.co.nz:/20040313/index.shtml">www.mysite.co.nz:/20040313
/index.shtml</font></td>

Control arrays in PHP offer significant advantages in processing form
input where there are a variable number of sets of the same elements
repeated multiple times down the page to allow a set of records of the
same data fields to be edited. The form elements are received back in the
processing script as an array which can be dealt with in a
straightforward for loop.

According to HTML 4.0 standards, the name of an Input element should
follow these conventions:

"NAME tokens must begin with a letter ([A-Za-z]) and may be followed by
any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), and periods (".")."

I don''t see anything there about the square brackets which are part of
the PHP array syntax, but they seem to be accepted and PHP seems to be
able to turn all the elements it receives into an array on the submission
of the form to the processing script. Is there something in the CGI
conventions or HTML that it does permit this syntax?


这篇关于PHP控件数组语法与HTML标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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