php – 如何在coldfusion中爆炸来自html表单的数组?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 如何在coldfusion中爆炸来自html表单的数组?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我是Coldfusion新手(截至今天).我不知道服务器使用的是什么版本.我已经阅读了 http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=Part_4_CF_DevGuide_1.html的一些内容,试图加快速度.

我现在面临一个重要问题是:这个PHP的ColDFusion等价物是什么?

$numatt = $HTTP_POST_VARS['numatt'];
$att=explode(",",$numatt);
$attcount = count($att);

这是上下文的整个PHP脚本:

<?PHP
$nument = $HTTP_POST_VARS['nument']; # this is one number. My debug example is 2.
$numatt = $HTTP_POST_VARS['numatt']; # this is an indefinITe number of numbers separated by commas. My debug example is 3,5.
$numval = $HTTP_POST_VARS['numval']; # this is one number. My debug example is 6.
echo 'number of entities is: $nument<br><br>';
$att=explode(",$numatt);
$attcount = count($att);
echo 'the attributes are $numatt,which can be broken down to $att[1] and $att[2].<br><br>';
echo 'there are $numval values for each attribute.<br><br>';
for ($i = 1; $i = $nument; $i++) {
    echo 'this is round $i of the loop. It has $att[$i] attributes.<br><br>';
    for ($j = 1; $j = $att[$i]; $j++) {
        echo 'this is for attribute $j of entity $i.<br><br>';
        for ($k = 1; $k = $numval; $k++) {
            echo 'here is loop $k for $numval values.<br>';
        } #end $k
    } #end $j
} #end $i
?>

基本上我需要将它从PHP翻译成ColdFusion,但是如果我在手册中花了足够的时间,我想我可以弄清楚如何设置循环. (或者我会回来提出更多问题……)对于更好的手册或入门参考的指针也会受到欢迎 – 我刚刚通过GOOGLE找到了上面链接的那个.

解决方法

在ColdFusion中,您可以使用listToArray()函数轻松地将字符串转换为数组.所有表单变量都在表单范围内捆绑在一起.所有url变量都在url范围内捆绑在一起.

<CFoutput>

    <!--- reference variables submitted through a form --->
    <p>name sent through form: #form.FirstName#</p>

    <!--- reference variable in url --->
    <p>name in url: #url.firstName#</p>

    <!--- output a list of all fields submitted in a form --->
    <p>all form field names: #form.fieldNames#</p>

    <!--- quickly dump form and url data (for debugging purposes) --->
    <cfdump var="#form#">
    <cfdump var="#url#">

    <!--- output all form field data --->
    <cfloop collection="#form#" item="key">
      Form field name: #key#,form field value: #form[key]#
    </cfloop>

    <!--- converting strings into arrays,default delimiter is comma --->
    <cfset arr1 = listToArray("my,list,is,cool",")>

    <cfset arr2 = listToArray("my other list"," ")>

    <cfset arr3 = listToArray("yet:another:list",":")>

    <!--- how many items in arr1? --->
    #arrayLen(arr1)#

    <!--- loop over arr3 --->
    <cfloop From="1" to="#arrayLen(arr3)#" index="i">
      #arr3[i]#
    </cfloop>

</cfoutput>

CFML使大多数事情变得简单.请记住,如果您不想使用标签,CFML还会提供脚本语法.

脚本宝典总结

以上是脚本宝典为你收集整理的php – 如何在coldfusion中爆炸来自html表单的数组?全部内容,希望文章能够帮你解决php – 如何在coldfusion中爆炸来自html表单的数组?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。