Convert ASP to PHP with ASPA

    Harry Fuecks
    Harry Fuecks
    Share

    If you’ve been around PHP a little, you’ve probably run into asp2php before, an app which attempts to convert ASP 3.0 code (VBScript mainly) to PHP automatically. I’ve mentioned this stuff before but recently been playing with something that looks serious.

    While asp2php is a brave project and I have no wish to knock it, from past experiments found it unconvincing. Yes it delivers something resembling PHP but the real issue is what still remains TODO – basically an 80/20 thing. And while that is to be expected with any tool of this kind, the problem is there’s no way to control what get’s generated, other than by modifying the C source.

    A while back, while looking for tools able to parse PHP1), run into ASPA, developed by Anakreon Mejdi: “ASPA attempts to automate the process of translating asp pages into php. The supported languages are JScript and VbScript.”.

    ASPA is written in Java and builds on top of ANTLR, a mature, Open Source parser generator framework. What makes it special, IMO, is it’s fairly easy to control the output PHP by virtue of XML “mapping” files which are loaded at runtime (during conversion). You’ll find this describe a little here (PDF).

    After playing with ASPA for a while, here’s a few notes / thoughts.

    – Expect to have to spend time installing – you’ve got usual Java pain to deal with here, including ant – I needed to rebuild ASPA. Here I’m only going to give hints based “it worked for me” on WinXP.

    – I used version 1.2 of ASPA. It lacks various dependencies namely antlr, log4j, dom4j and commons-collections, which Anakreon describes. A quick way to get them all is to download the 1.1 of ASPA which has them all in the ./lib subdirectory – just copy across the v1.2 ./lib subdirectory. What’s missing though is the Jaxen .jar, which also needs to go into the ./lib directory – you can get a built version from here

    – If you look in the ./etc/log4j.properties file you’ll find it identifies a log file like log4j.appender.FILE.File=logs/log.txt – this is relative to the base ASPA directory and you’ll need to make sure this file / directory exists. Once you have ASPA built with ant, the aspa-1.2/build/classes/gr/omadak/leviathan/asp/log4j.properties file can be used to control how much logging happens every time you convert

    – With ASPA built, the XML translation files can be found at aspa-1.2/build/classes/gr/omadak/leviathan/asp/objects. I believe (not tested) you can create new XML files here with filenames corresponding to the ASP / ActiveX objects you want to convert to PHP as described here (PDF). While what ASPA does here is a great start, it strikes me that to really empower users, something like Rhino or Jython is needed, combined with access to parse time information from ASPA.

    – To put it to the test, I picked the first ASP Blogging app, published under GPL, that I could find via Google – Ublog. For comparison, I’ve dumped the results here along with the ASPA log file. Haven’t modified that or done any significant tuning of the output. Basically it’s at the 80% mark I’d guess. Some files it failed to convert, as explained in the log. Other things like calls to require name a .asp which will have been converted to a .php file so no longer exist. Meanwhile some thought need to go into XSS implications of all those print statements. And thought is needed as to whether APIs have been translated in the smartest manner e.g. the DB calls which ASPA primes for use with John Lim’s ADODB but look to be about 90% there API-wise. But the donkey work has been done – the last 20% is doable and by pushing at much as possible into the XML translation files, it may be possible to get down to 5% or lower.

    Overall ASPA is looks to be very much at the “it works” stage but now needs to aim for “it’s accessible”. In particlar the ability to modify the output PHP fairly easy marks it as significant and there’s potentially a serious tool for “the masses” here, if an easy to install binary distribution can be put to together and, better yet, if a GUI to be stuck on top to help manage conversions (e.g. the XML translation files are “global” to ASPA but their use would likely be application specific). In it’s current form I guess this would be a big help to ASP developers interested in having PHP versions of their code. There’s also opportunity to inject some kind of PHP framework into the mix, as the target output API – one that’s primed to support common ASP idioms.

    Side note: What led me to ASPA was looking for tools able to parse PHP scripts, for doing something like a PHP lint. Interestingly there are hardly any that really “understand” PHP and when they do, it seems to lead to people wanting to keep the results closed source. Aside from hand coded stuff like phpxref, two exceptions are scintilla (which you can tap into in Python via SilverCity or wx.STC but the tokens are very general) and spident (which was more Java than I cared to submit myself to).

    Frequently Asked Questions on Converting ASP to PHP

    What are the key differences between ASP and PHP?

    Active Server Pages (ASP) and PHP are both server-side scripting languages used for web development. However, they differ in several ways. ASP is a Microsoft product and runs on IIS (Internet Information Services) installed on a Windows platform. On the other hand, PHP is an open-source language and runs on various platforms like Windows, Unix, and Linux. PHP is generally considered to be faster and more efficient than ASP. It also has a larger community of developers, which means more resources and support.

    Why should I convert my ASP code to PHP?

    There are several reasons why you might want to convert your ASP code to PHP. PHP is open-source, which means it’s free to use and has a large community of developers contributing to its development. It’s also platform-independent, so you can run your website on any server. PHP also tends to be faster and more efficient than ASP, which can improve the performance of your website.

    How can I convert my ASP code to PHP?

    Converting ASP code to PHP can be a complex process, especially if you’re not familiar with both languages. However, there are tools available that can help with this process. For example, ASPA is a tool that can convert ASP code to PHP. It’s important to note that these tools may not be able to convert all aspects of your code, so you may need to manually adjust some parts.

    Are there any limitations to converting ASP to PHP?

    While tools like ASPA can help with the conversion process, they may not be able to convert all aspects of your ASP code to PHP. For example, they may not be able to convert ASP components or certain ASP functions. In these cases, you will need to manually adjust your code.

    Can I convert ASP.NET code to PHP?

    Yes, it’s possible to convert ASP.NET code to PHP, but it can be a complex process. There are tools available that can help with this process, but they may not be able to convert all aspects of your code. You may need to manually adjust some parts of your code.

    What should I do if I encounter errors during the conversion process?

    If you encounter errors during the conversion process, it’s important to carefully review your code to identify the issue. You may need to manually adjust parts of your code. If you’re not familiar with PHP, you may want to consider hiring a PHP developer to assist with the conversion process.

    How can I test my PHP code after conversion?

    After converting your ASP code to PHP, it’s important to thoroughly test your code to ensure it’s working correctly. You can do this by running your PHP code on a server and checking for any errors or issues.

    Can I convert my ASP code to PHP without any programming knowledge?

    While it’s possible to use a tool to convert your ASP code to PHP, it’s likely that you will need to manually adjust parts of your code. This will require some knowledge of PHP. If you’re not familiar with PHP, you may want to consider hiring a PHP developer to assist with the conversion process.

    How long does it take to convert ASP code to PHP?

    The time it takes to convert ASP code to PHP can vary depending on the complexity of your code and your familiarity with PHP. Using a tool can speed up the process, but you may still need to manually adjust parts of your code.

    Can I convert my ASP code to other languages besides PHP?

    Yes, it’s possible to convert your ASP code to other languages. The process will depend on the language you’re converting to. You may be able to find tools to assist with the conversion process, or you may need to manually adjust your code.