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

标签 php html coldfusion

我是 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,但如果我花足够的时间阅读手册,我认为我可以弄清楚如何设置循环。 (或者我会带着更多问题回来......)也欢迎指向更好的手册或入门引用的指针 - 我刚刚通过谷歌找到上面链接的那个。

最佳答案

在 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 还提供脚本语法。

关于php - 如何在 coldfusion 中分解来自 html 表单的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26287494/

相关文章:

php - 从循环php将一行插入mysql

php - 条件 PDO bindParam 更新

html - 页面底部的水平滚动导航栏

php - 在 ColdFusion 中验证来自 Microsoft Teams 自定义机器人的 HMAC

php - 每天显示一次 div

PHP5 : Find Root Node in DOMDocument

javascript - 如何显示前 X 个字符,然后单击 href 以显示其余字符。

html - 在不使用框架的情况下在具有固定内容的页面上滚动菜单

mysql - 如何按点击状态对表格进行升序和降序排序? MySQL/ColdFusion

coldfusion - Twitter、oauth 和 Coldfusion