12

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?

Otherwise, is there an extensive table that lists comparisons (such as design215.com/toolbox/asp.php)

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Peter Craig
  • 7,101
  • 19
  • 59
  • 74
  • 13
    http://en.wikipedia.org/wiki/Human These work fairly well, although the required maintenance makes them cost-prohibitive systems to operate. – Annath Jun 05 '09 at 05:57
  • I am now stuck on a connundrum as our programmer is trying to talk us into converting to PHP/APACHE for Coopers Pick instead of going from .asp to .Net. What should I do here? What are the benefits of converting to php opposed to .Net and how long should a transfer to php take? –  May 14 '11 at 14:45

3 Answers3

12

It isn't perfect, but this will convert most code.

Bond
  • 16,071
  • 6
  • 30
  • 53
Abinadi
  • 660
  • 4
  • 9
  • 4
    My laughing at the question was instantly cut short by your response. I'm amazed such a tool exists. – Gerry Jun 05 '09 at 08:14
  • I did think it was a tall ask and wasn't interested in a direct working conversion, just something that would explain some of the unknown syntax etc and this tool does exactly that. – Peter Craig Aug 02 '09 at 23:34
  • exactly what i needed for a project that just came my way :) – Amb3rL4nn Jun 17 '16 at 14:15
1

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.

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • I understand this is a poor way of doing it but for me it's simply to understand more easily how the old code or sample works to go ahead and implement in PHP. – Peter Craig Jun 05 '09 at 06:13
0

I agree with Abinadi that the tool by Mike kohn here is probably the best available still.

We did a successful conversion for a decent size project and wrote a blog about the process: 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.

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.

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

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.

Good luck to anyone attempting this conversion project, having done it before we know the feeling.

Matt B
  • 53
  • 5