如何在coldfusion中分解来自html表单的数组


how do I explode an array that came in from an html form in coldfusion?

我是ColdFusion的新手(事实上,截至今天)。我不知道服务器使用的是什么版本。我已经通读了一些http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=Part_4_CF_DevGuide_1.html试着跟上速度。

目前我最大的问题是:ColdFusion对这部分PHP的等效性是什么?

$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,但如果我在手册中花足够的时间,我想我可以弄清楚如何设置循环。(或者我会带着更多的问题回来…)也欢迎指向更好的手册或入门参考资料的人——我刚刚通过谷歌找到了上面的链接。

在ColdFusion中,您可以使用listToArray()函数轻松地将字符串转换为数组。所有表单变量都在form作用域中为您打包。所有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还提供了脚本语法。