将PHP文件解析为ASP扩展
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将PHP文件解析为ASP扩展相关的知识,希望对你有一定的参考价值。
For those cases where you want to code in php but need to deploy to ASP. It doesn't account for php logic but only converts the php include() statements into SSI includes. Could be useful for converting basic websites from php to asp, rare but it happens :)
<?php /* ## Convert from PHP to ASP extensions with SSI includes ## getFiles() - Get all php files from root / includes directory stripIncludes() - Regex php syntax and includes for SSI saveFile(filename) - Save string to (.asp) file extension while preserving the filename ## Concept - 1) function getFiles( directory ) - all php files from directory and loop through each 2) function parseDir( directory ) - copy file to .asp extension and remove the .php version - replace php includes with SSI then save file ## Examples: //parse includes folder '/inc' or use $_SERVER['DOCUMENT_ROOT'] parseDir( dirname( __FILE__ ) . '/inc/' ); //parse root parseDir( dirname( __FILE__ ) ); */ //copy all of your php source into another directory, replace 'asp_directory' and set to your export path parseDir( $_SERVER['DOCUMENT_ROOT'] . '/asp_directory/' ); parseDir( $_SERVER['DOCUMENT_ROOT'] . '/asp_directory/inc/' ); function getFiles($dir){ //start with root files $files = ''; //loop through all of the files $files[]=$file; } } } return $files; } function parseDir($dir){ foreach( getFiles( $dir ) as $file ){ if( $file != 'convert.php' && $file != '' ){ //parse all files except this one $fpath = $dir . $fname;//new filename and path $orig = $dir . $file; //copy from php to asp extension }else{ print "Error: unable to copy file " . $orig . " - to - " . $fpath . " <br>check file permissions"; } //remove the old php version //read the file contents into a string for replacements //replace the php include statements with SSI virtual includes $file_str = str_replace( "<? include('", '<!--#include virtual="', $file_str ); // 'virtual' = relative path //if the file is writeable then proceed //write the new string to the .asp file - just as it should be (plain text) }else{ print 'Error: Cannot write to directory, check permissions on' . $fpath; exit; }//end if }//end if file print "parsed: " . $fpath . "<br />"; }//end foreach }//end parseDir ?>
以上是关于将PHP文件解析为ASP扩展的主要内容,如果未能解决你的问题,请参考以下文章