ASP to PHP Readme. Version 44. ============================== Copyright (C) 2003 Pharmease, Inc. Author: Konstantin Kirillov. QUICK USAGE FOR SITE/FILE WHICH CONVERTS BY ONE BUTTON CLICK. ============================================================= This section is for occasional/new user who is not concerned about advanced details. Run Script2Script. Following "Simple Usage" instruction in file Examples\readme_and_license.htm, point to your source file or folder to convert. After conversion, put RESULT_FILES to web root. Remove comment characters "//" from the statement: <?php // require("../../replacers.inc"); in result files to link asp-php wrappers to converted files. ( If source asp-site had nested "include" statements, don't uncomment "require" in children files to do not include file "replacers.inc" twice or more. If source project has nested folders structure, check that "require" statement has accurate number of "../" and accurately points to "replacers.inc". ) Point web browser to the front page of converted site. This can be: www.your_domain_name.com/RESULT_FILES/index.php in which case index.php is the name of front page. Default test project which definitely converts by one click is "messenger". The end of "QUICK USAGE" section. More thoughtful approach may include following steps. GLOSSARY ======== SITE - Site, file, folder, ASP project to convert, or ASP Application is called SITE or SOURCE here. SOURCE - The same. RESULT - Converted result called RESULT. Compi - This converter is called Compi. WRAPPER - PHP construct which used in the same way as original ASP construct in the code. Iside itself, PHP construct, however, has interface to PHP-core or to PHP-functions. If WRAPPER wraps a function, then WRAPPER has the same header as ASP function. If WRAPPER wraps method or property this can create more complex structures. Two default wrap libraries are included in distribution: custome.inc contains PHP-equivalents for commonly used application-specific procedures; replacers.inc has few equivalents of ASP langauge-core functions and object methods and properties; THIS SCHEMA CONVERTS ==================== * Genric BASIC syntax (if-then, do, select case ... ) to C-like syntax used in PHP. Which structures are converted can be seen in schema. * Casts term type: function, variable, array, constant, or number. * Recongizes globals used in subroutines and functions. * Preserves SOURCE folder structure and copies graphics and other neutral files to the RESULT. * more details provided in schema_readme.txt WHAT THIS SCHEMA DOES NOT CONVERT ... ===================================== ... briefly: - run-time-platform-dependent restrictions; please see Appendix A; - not all functions/object_methods/properties/database methods/ converted to their PHP equivalents; - assumes that SOURCE is written in "Option Explicit" style; - assumes that there is only one name space for an entire SITE; - does not make difference between "arguments by reference" or "by value"; ... details are in following explanations and instructions: RECOMMENDED CONVERSION STEPS ============================ * Reader may try and learn from included sample-projects sml and messenger. * WRAPPERS. This may be important for complex projects. To add default wrappers, uncomment, or edit lines: <?php require( "../custom.inc" ) ?> <?php require("../replacers.inc") ?> in certain modules after converter is run. Converter puts this two *.inc files to parent folder of result. Compi wraps few ASP-object methods and properties to PHP functions. Not all functions/object_methods/properties/database methods/ converted to their PHP equivalents. Reader may look at this files, analyse them, and follow pattern in schema and replacers.inc to add more wrappers. Section "00000" of file wrapping.txt contains some patterns. Schema and replacers.inc contain information about which constructs will be converted. Section "OOO00" contains an example for object "Response". Non-converted names are preserved in RESULT and are added characters "!!" or "!!_c_" to simplify their search. Programmer can browse them and convert manually. * Generally VB and PHP have the same precedence. Most striking difference makes negation not --> ! ( not a>b is not(a>b) in ASP. !a>b is (!a)>b in PHP. ) Compi does not do any precedence conversion at all, so programmer should put parenthesis manually if needed before or after conversion. * Reader may debug and test ASP application before conversion. IT IS HELPFUL to run ASP-project with "Option Explicit" before conversion, because this helps to catch all undeclared variables. Non-working application converted to PHP may become harder to manage. * Schema assumes that SOURCE is written in "Option Explicit" style. In other words, all names which are not explicity declared as variables or arrays will be interpreted as functions, which implies missed prefix "$" and added postfix "()" at the name. * Set "risky" conversion options. They are not required, but may decrease amount of work. To set them, please go to marks '!* in schema. * Reader may use techinique to convert two times: with risky options and without and then compare RESULTS. Combination of "FolderComparer" and MS-Dos program "fc" can be used for comparision work. * This is an actual conversion step. Convert SOURCE. Menu/Go can be used. Menu/Run is designed for brief tests. * Look at possible console exception messages. If console was resaved, please look in file console.txt. * If exception happens when Compi parses function for the first time, the text preceding exception may not be printed. In this case, earlier option_explicit13.txt version of schema can be used. * Search for Compi's warning marks //! and !! in RESULT. Please see M A R K S ... section what do they mean. * If "risky" option ".asp --> .php fragments" was not set, but has to be done, then scan RESULT for ".asp" and change them to ".php" manually. * Search for characters "\" which may be part of file-system names and change them to Unix-like. * Schema does not recognize function-argument calls by reference. Consider that some function arguments in your project require call be reference. You may prepend ampersand in function definition, but be sure that this will not case another conflicts. (Schema can be redesigned to prepend ampersand to each parameter in procedure call like "¶meter", but this may not be good for most of the calls like this not good to make this for functions "replace( byRef s, byRef r, byRef z) or for Abs(byRef x)".) * S2S converts ASP "Const" statements to PHP "define" contstruct. This is correct for ASP global constants. ASP local constants declared inside Sub and Function procedures, become global after conversion because all constants in PHP are global. If your project has local constants, they should be corrected manually after conversion. * Debug RESULT and make more manual correctios if any. * There may be too much comment text in RESULT. It can be stripped for faster performance. * ASP and PHP may have include-tree structure. Each target URL initiates script which have name-space which may be different for another target. For example, variable my_function in one page can be declared as function my_function (x) response.write x end function and in another page, as dim my_function(3) which is an array. This schema assumes that there is only one name space for an entire SITE. * Schema converts <!--#include ... statement. In ASP "include" is relative to a file. In PHP "require" is relative to a top parent. Reader may have to adjust paths. * Construct "for each" does not cause Compi to stop, but marked in RESULT for manual correction. * Minor manual work may be required if source script has <!--#include ... > construct on single line, and response.redirect ... is located after it: terminating LF will be sent to browser before header(... executed: manually delete all spacers outside of php-script. There is one example: '=============================================================================================== ' ASP example: '----------------------------------------------------------------------------------------------- For Each item In Request.Form item_name = cstr(item) 'item's name item_value = Request.Form(item_name) 'item's value ... if left(item_value,1) = "$" then ... '=============================================================================================== //=============================================================================================== // Possible PHP equivalent of above example: //----------------------------------------------------------------------------------------------- foreach($_POST as $item_name => $item_value) { ... if(substr($item_value,0,1)=="$"){ ... //=============================================================================================== * Compi converts ASP construct "request(..." to PHP construct "${ ... " which may be wrong. I do not know this. If it is wrong, this can be easily found in RESULT and fixed. M A R K S I N S C H E M A A N D R E S U L T ====================================================== Marks in schema start with pair of characters: '! ------------------------------------------------- '!~ conversion is clearly non-precise; '!* risky methods to be used in schema; uncomment schema-statement to activate; (risky method can save significant manual work;) '! manual correction may be required; '!! manual correction required for sure; '!L logical version of construct has been used; reader can change to bitwise; '!b bitwise version of construct has been used; reader can change to logical; '!+ optional or adjustable. does not affect result script functionality; but may change a text formatting. '!M construct may have different meaning in PHP than in ASP; for example randomize and srand; 'R needs text proofreading to confirm PHP-match; All marks in RESULT start can be found by searching for ------------------------------------------------------- two character combinations: //! or !! //! manual correction may be required; //!! manual correction required for sure; //!!! manual correction required for sure; //!N check for possible naming conflict; _c_ - postfix at function names and variables which bear function name in "function" subroutines. Schema can add more function names when wrapping. All of them will have postfix which contains _c_ Wrap-functions have "_c_". "Function fun" uses variable "$fun" to enable "return fun;"; It is assumed that there is no conflict between name of function "fun" and name of variable "$fun", although author has NEVER SAW this stated in php manual http://www.php.net/manual and still searches for it. !! - postfix at term name. Manual correction requiered. !!_c_ - postfix at fucntion name. Manual correction requiered. WHAT IF YOUR SOURCE PROJECT HAS BUGS ==================================== * Undeclared variables. These can be hard to find. However, they will not have prefix "$", may have parenthesises "()" and may be detected by PHP Warnings. This may help to discover non-declared variables in other files. However, php-compiler may report exception without explanation, and it is hard to locate this exception. * Compi is not a syntax-checker. Often, however, when source syntax is broken, Compi gives message on console, and terminates at specific place in text, but does not terminate all project. COMPLEX CODING STYLES IN SOURCE =============================== * Very unlikely. If fragments of function or control structure or parts of statement are split between includes and include callers, this schema may not work correctly. F.e., program <%x = %> <!--#include file="assign.inc"--> <% = 4%> where file assign.inc contains <% sin(3) y %> will not be converted correctly. LESS IMPORTANT TO KNOW ====================== * Schema tune up. It is hard to make significant changes in this schema because it became very long. * Schema loweres case for term names. VB thinks that MyVariable and myvariable are the same. To turn this feature off, issue command: ..env_output_case = "N" * Schema converts <%= VB string constant with double characters "" inside. * Some script constructs interpreted as bitwise operations. Make corresponding replacements marked '!b if you like to use only for boolean variables. * ^ operation is not converted, but you can convert result text manually using that in result text it will be replaced with pow!! * the same for imp.k ---> imp!! * \ ---> / is '~ In ASP, \ is int-division. * In schema, action .i prepares line feed and indent to be used for following output. Therefore, .i .i does the same as .i APPENDIX A. PRINCIPAL ASP TO PHP CONVERSION RESTRICTIONS ======================================================== 1. Indirect rereferences to renamed Built-in ASP Objects: Application, ObjectContent, Request, Server, Session may not be converted correctly. For example: if x="weather_is_good" then set ob = response else set ob = err end if ob.clear will not be converted correctly, because schema does not know which value will x have at run-time and does not know where does method "clear" belongs: to response or to err object. 2. Run-time calls to file system. File name variable value can have character "\" which is incorrect for Linux and is not checked. To protect against 1 or 2, reader should proof-read the SOURCE or RESULT. REFERENCES ========== PHP manual: http://www.php.net/manual/ PHP info abut your site: http://YOUR_SITE.COM/phpinfo.php PHP versus ASP: http://www.zend.com/zend/art/langdiff.php PHP versus ASP and JS: http://php.weblogs.com/php_jscript_vbscript_1 PHP objects versus ASP: http://php.weblogs.com/php_asp_objects PHP string manual http://www.zend.com/zend/tut/using-strings.php#operations ASP (local Windows) W98 local http://localhost/iishelp/iis/htm/asp/iiapwelc.htm asp applications W98 http://localhost/iishelp/VBScript/htm/VBStoc.htm VBScript W98 http://localhost/iishelp/iis/htm/asp/intr1orp.htm asp objects W98 http://localhost/iishelp/iis/htm/asp/comp275c.htm installable objects 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm Please send you notes, bug reports, recommendations to script@pharmease.com. We cannot guarantee response, but will do our best. 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm