Here's a set of find/replaces I'm doing to convert large blocks of PHP code to Python:
remove "<?php" or "?>" anywhere they appear
s/;$// #remove trailing semicolons
s/\$// #remove dollar signs
s/.=/+=/ #change concatenation to Python syntax
s/array\(/[/ #though, that's only right in some cases
s/list\(/\(/
s/\s*=>/:/
s/->/./
s/if\((.*)\){/if $1:/ #remove any parentheses around ifs
s/}// #
s/elseif/elif/
s/else{/else:/
s/echo/print/
s/NULL/None/i
s/++/+=1/
s/is_numeric\(([^ ]*)\)/$1.isdigit()/
s/strlen/len/
And seriously, that's most of the work involved... at least, most of the tedious work. I could automate more things, but at this point you start to get diminishing returns. For instance, I could write a regular expression to change "array_key_exists(key, arr)" into Python's "key in arr", but it starts being more trouble than it's worth. Ooh, I could even change expressions using PHP's ternary operator into Python expressions, which goes something like:
foo ? bar : baz => foo and bar or baz
Although if bar's false you'll still get baz, though that's often what you want anyway. I often use PHP ternary operators to do something like isset($foo[$bar]) ? $foo[$bar] : false to avoid getting PHP's notices, for instance.
By the way, these regular expressions aren't exactly what I'm using. I'm just doing find/replaces in EditPlus; I'm not parsing the file with Perl or anything. I just used Perl syntax to explain the find/replaces I'm doing in the most concise way possible. Sorry if there are any errors. And I know, I need the "g" modifier on all of those.
Don't you think it's time to stop showing "PHP Rocks" on the bottom? :-)