这是当前的 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);
}
?>
`
最佳答案
我不太了解 PHP,但我可以推断出一些东西,也可以用 google 搜索一些东西。如果我弄错了,请有人纠正我。
- > isset() : 虽然不是直接类比,但应该使用 structKeyExists()像这样进行变量检查。
isset()
大部分直接等同于 isDefined() , 但如果可能的话,应该避免isDefined()
,因为它有返回误报的倾向; - > $_POST variables与 FORM 范围的变量相同;
- > stripslashes()取消转义字符串中转义引号的反斜杠;
.
(点)是 string-concatenation operator , 就像 CFML 中的&
;- > fopen()打开一个文件,“w”参数打开它进行写入。所以就像 fileOpen() 的等效用法在 CFML 中。
- > fwrite()写入所述文件。
=== false
位检查是否存在文件写入错误,这在 CFML 中没有直接的等效项,所以我想类比是放置一个 try/catch文件操作(无论如何都应该始终执行)。- > echo()相当于writeOutput() (或者只是
); - > fclose()与fileClose()相同.
就是这样:我认为其余部分是不言自明的。
我要说的是,很容易(正确地~)猜测所有这些东西,或者用谷歌搜索。我只是用谷歌搜索“php fopen”、“php dot operator”等(主要是为了获取文档链接)。所以您或许可以自己完成此操作。
关于php - 需要帮助将我的 PHP 应用程序转换为 Coldfusion。谁能帮忙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13637596/