需要帮助将我的PHP应用程序转换为Coldfusion。谁能帮助

时间:2012-11-30 01:12:50

标签: php coldfusion

这是当前的PHP,不知道如何开始转换为Coldfusion。我需要在我的coldfusion服务器上发布它。

<?php
/**
 * Saves POST input as an XML file and returns a JSON response
 */

$xmlString;

if (isset($_POST['xmlString'])){
$filename  = $_POST['xmlFilename'];
$xmlString = stripslashes($_POST['xmlString']);

$newFile = "_data/".$filename.".edit.xml";

//write new data to the file, along with the old data 
$handle = fopen("../".$newFile, "w"); 
if (fwrite($handle, $xmlString) === false) { 
    echo "{error:\"Couldn't write to file.\"}";  
} 
else {
    //echo "{filename:\"".$newFile."\"}";
    echo "success:::$newFile:::$xmlString";
}
    fclose($handle);    
}
?>
`

1 个答案:

答案 0 :(得分:7)

我不太了解PHP,但我可以推断出东西,我可以谷歌的东西。如果我弄错了,有人可以纠正我。

  • isset():虽然不是直接类比,但应该使用structKeyExists()来进行变量检查。 isset()大部分直接等同于isDefined(),但如果可能的话,应该避免isDefined(),因为它有返回误报的倾向;
  • $_POST variables与FORM范围的变量相同;
  • stripslashes()取消了在字符串中转义引号的反斜杠;
  • .(点)是string-concatenation operator,与CFML中的&类似;
  • fopen()打开一个文件,“w”参数打开它进行写入。就像CFML中fileOpen()的等效用法一样。
  • fwrite()写入该文件。
  • === false位检查是否存在文件写入错误,其中没有直接等效的CFML,所以我猜这个类比就是在文件操作中放置一个try / catch(哪一个)应该总是这样做。)
  • echo()相当于writeOutput()(或只是&lt; cfoutput&gt;);
  • fclose()fileClose()相同。

就是这样:我认为其余部分是不言自明的。

我要说的一件事是,(正确〜)猜测所有这些东西,或谷歌它很容易。我只是用Google搜索“php fopen”,“php dot operator”等(主要是为了获取文档的链接)。所以你自己也许可以做到这一点。

相关问题