将 ASP 转换为 PHP 的工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/954405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tool to convert ASP to PHP
提问by Peter Craig
I program mostly in PHP and have a site along with other samples in ASP I need to convert over to PHP. Is there some kind of "translator" tool that can either enter lines of code or full slabs that attempts to output a close PHP equivalent?
我主要使用 PHP 进行编程,并且有一个站点以及 ASP 中的其他示例,我需要将其转换为 PHP。是否有某种“翻译器”工具可以输入代码行或试图输出接近 PHP 等效项的完整平板?
Otherwise, is there an extensive table that lists comparisons (such as design215.com/toolbox/asp.php)
否则,是否有一个广泛的表格列出比较(例如design215.com/toolbox/asp.php)
回答by Matthew Flaschen
I think this is a poor way to do it. Sure, a quick-reference table helps a little. But really you need to be fluent in both ASP and current PHP best practices, and envision what a good PHP design would be. The naive transliteration will just give you PHP code that thinks it's ASP. A true port will be easier to understand and maintain.
我认为这是一个糟糕的方法。当然,快速参考表会有所帮助。但实际上,您需要精通 ASP 和当前的 PHP 最佳实践,并设想一个好的 PHP 设计。天真的音译只会给你认为它是 ASP 的 PHP 代码。真正的端口将更易于理解和维护。
回答by Matt B
I agree with Abinadi that the tool by Mike kohn hereis probably the best available still.
我同意 Abinadi 的观点,这里Mike kohn 的工具可能仍然是最好的。
We did a successful conversion for a decent size project and wrote a blog about the process: Converting Classic ASP to PHP
我们为一个体面规模的项目成功进行了转换,并写了一篇关于该过程的博客:Converting Classic ASP to PHP
While a standard lookup table with function could work it would be a LOT of work still to clean everything up. ASP to PHP is still probably one of the easier conversions but as mentioned will most likely end up with code that potentially is bad but in a different language.
虽然具有功能的标准查找表可以工作,但清理所有内容仍然需要大量工作。从 ASP 到 PHP 仍然可能是更容易的转换之一,但如前所述,很可能最终会得到可能很糟糕但使用不同语言的代码。
Mike's tool handles fairly basic single page conversions and a good starting point but was outdated, missing a lot of functions and smarts when used on a bigger project. In saying that, it's still worth trying out even in the current state.
Mike 的工具处理相当基本的单页转换和一个很好的起点,但已经过时,在更大的项目中使用时缺少许多功能和智能。话虽如此,即使在目前的状态下,它仍然值得一试。
Here's a list of the main points we had to consider:
以下是我们必须考虑的要点列表:
- Not all types have a compatible type, eg dates and booleans
- COM Objects can be used but may need heavy refactoring
- Variable case sensitivity (tools can help here a lot)
- Variable scoping (asp loves globals)
- HTML/JS Get and Post case sensitivity (harder to fix with tools)
- Object self references, eg PHP classes need $this->variable
- If you use lots of let/get/set be prepared for some heavier re-factoring
- 并非所有类型都有兼容的类型,例如日期和布尔值
- 可以使用 COM 对象,但可能需要大量重构
- 可变大小写敏感度(工具在这里很有帮助)
- 变量范围(asp 喜欢全局变量)
- HTML/JS Get 和 Post 区分大小写(使用工具更难修复)
- 对象自引用,例如 PHP 类需要 $this->variable
- 如果您使用大量的 let/get/set 准备进行一些更重的重构
Of course the list above is just things to lookout for, if you were to create a tool you have to factor in a lot of the basics in parsing/tokenising asp code before even considering the above differences.
当然,上面的列表只是需要注意的事情,如果您要创建一个工具,则在考虑上述差异之前,您必须考虑解析/标记化 asp 代码的许多基础知识。
Good luck to anyone attempting this conversion project, having done it before we know the feeling.
祝任何尝试这个转换项目的人好运,在我们知道感觉之前已经完成了。

