2014-10-09 69 views
3

我是ColdFusion的新品牌(截至今天)。我不知道服務器使用的是什麼版本。我已閱讀http://help.adobe.com/livedocs/coldfusion/8/htmldocs/help.html?content=Part_4_CF_DevGuide_1.html中的一些內容以嘗試加快速度。我如何分解一個來自ColdFusion中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,但認爲我可以弄清楚如何建立循環,如果我花足夠的時間在手冊中。 (或者我會回來更多的問題...)指向更好的手冊或入門參考也將受到歡迎 - 我剛剛通過谷歌找到了上面鏈接的那個。

+2

你會喜歡這個頁面:http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec1a60c-7ffc.html – 2014-10-09 20:53:49

+1

*剛剛發現了一個通過谷歌* Adob​​e的文檔上面鏈接是開始的好地方。大部分函數名稱都是不言自明的。如果您不知道函數名稱,但是有一個想法應該做什麼,[類別功能](https://wikidocs.adobe.com/wiki/display/coldfusionen/Functions+by+category)也很有用。 – Leigh 2014-10-09 20:58:21

+2

注意,您可以通過登錄到CF管理器來獲取版本號 - 或者 - 通過轉儲服務器變量:'' – Leigh 2014-10-09 21:05:46

回答

6

在ColdFusion中,您可以使用listToArray()函數將字符串轉換爲數組。所有表單變量將在form範圍內爲您捆綁。在url範圍內,所有的url參數都會被捆綁在一起。

<!--- 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> 

<!--- 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> 

CFML使大多數事情變得簡單。請記住,如果您不想使用標籤,CFML還會提供腳本語法。希望幫助

+0

+1。也大多數範圍是結構,所以你也可以使用關聯數組符號,即'URL [「firstName」]或'FORM [「firstName」]''。有關更多信息:[關於CFScript](https://wikidocs.adobe.com/wiki/display/coldfusionen/About+CFScript) – Leigh 2014-10-09 21:03:44

+0

或者您可以完全忘記陣列並使用列表。 – 2014-10-10 10:01:03

相關問題