Convert PHP to ASP

Conversion issues

Convertor source

PHP vs ASP

Feedback / Contact us

The following code is the convertor page, exactly as it appears here. It was built 'quick and dirty' for a one-off internal project and therefore may seem a bit opaque and longwinded at times.

This page imports the html file php-asp_equivalents.htm. for the function equivalents list.

You may use this code, and php-asp_equivalents.htm for your own use, provided that you agree to:

  1. allow us to add your improvements to both the convertor and its data file.
  2. credit us with a link if you place this code, or anything derived from it, on a publicly accessible web server..

Enjoy...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<HTML>
<HEAD>
  <TITLE>PHP - ASP convertor</TITLE>
<style type="text/css">
<!--
td { font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #000000; text-decoration: none}
span { font-family: Arial, Helvetica, sans-serif; font-size: 16px; color: #000000; font-weight: bold; text-decoration: none}
A { text-decoration:none color:#003300 }
A:hover { color:#660000 }
-->

</style>



</head>

<body bgcolor="#FFFFFF" text="#000000" link="#003300" vlink="#003300" alink="#660000">


<table width="800" border="0" cellspacing="1" cellpadding="1">
<tr>
<td valign="top"><img src="../php-asp-convertor.gif" width="100" height="106">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<p>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="simonp@influenca.com">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="tax" value="0">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</p>
<p>
<script type="text/javascript"><!--
google_ad_client = "pub-0833314467244560";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel ="";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</p>
</form></td>
<td><?

$function_count=0;
$matchedfunctions=0;

function white_space($char){
  $whitespace=' '.chr(13).chr(10).chr(9).' ';
  for ($i=0; $i<strlen($whitespace); $i++){
    if ($char==$whitespace[$i])
    $white=1;
  }
  return $white;
}


function add_code_at_top($match){
  //echo 'adding code at top'.$asp_top[$match];
  global $asp_top;
  global $asp_top_code;
  global $asp_top_functions;
  if ($asp_top[$match] && !strpos($asp_top_functions,','.$match.',')){
    $asp_top_functions.='!,'.$match.','; // list of what's already included so we don't add functions more than once
    $asp_top_code.=chr(10).$asp_top[$match];
  }
}


function printout($string){
  for ($i=0; $i<strlen($string); $i++){
  echo $string[$i];
  if (ord($string[$i])<32)
  echo '['.ord($string[$i]).']';
  }
}

function htmldecode($string){
  $string=str_replace('&gt;','>',$string);
  $string=str_replace('&lt;','<',$string);
  $string=str_replace('&quot;','"',$string);
  $string=str_replace('&nbsp;',' ',$string);
  $string=str_replace('&amp;','&',$string);
  return $string;
}


function findend($end,$current_position){
  // ending is what we're looking for. nl= new line
  global $php_file;
  $new_position=$current_position;
  $endchr=chr(10);
  while ($php_file[$new_position]!=$endchr && $new_position<$end){
    $new_position++;
  }
  return $new_position;
}

function trimspace($string){
$string=str_replace('
','@#!NEWLINE!',$string);
$string=trim($string);
$string=str_replace('@#!NEWLINE!','
',$string);
return $string;
}
// *********************************************************
function set_functions(){
  global $php_functions;
  global $asp_functions;
  global $asp_endings;
  global $asp_top;
  global $asp_bottom;
  global $bracketstack;
  $bracketstack=array();

  $page= fopen("php-asp_equivalents.htm", "r") or die("can't open file");
  $pagestring=fread($page, 3000000);
  fclose ($page);
  $pagestring=str_replace(chr(10),'',$pagestring);
  $pagestring=str_replace(chr(12),'',$pagestring);
  $pagestring=str_replace(' ',' ',$pagestring);
  $pagestring=str_replace('   ',' ',$pagestring);
  $pagestring=str_replace(' ',' ',$pagestring);
  $pagestring=str_replace('<br>&nbsp;',chr(10),$pagestring);
  $pagestring=str_replace('<br> ',chr(10),$pagestring);
  $pagestring=str_replace('&quot;','"',$pagestring);
  $pagestring=str_replace('<p>','',$pagestring);
  $pagestring=str_replace('</p>','',$pagestring);
  $pagestring=str_replace('<br>',chr(10),$pagestring);
  $pagestring=str_replace('</td>','',$pagestring);
  $pagestring=str_replace('</tr>','',$pagestring);

  $pagestring=htmldecode($pagestring);
  $rows=explode('<tr>',$pagestring);

  for ($i=2; $i<count($rows); $i++){
    $parts=explode('<td>',$rows[$i]);
    $php_functions[$i-1]=trimspace($parts[1]);
    $asp_functions[$i-1]=trimspace($parts[3]);
    $asp_endings[$i-1]=trim($parts[4]);
    $asp_top[$i-1]=trim($parts[5]);
    $asp_bottom[$i-1]=trim($parts[6]);
  }
  // and now add the other functions

}

// ********************************************************************
function find_function($position,$endblockposition){
  // this function goes through the functions, finds a match, and sets global variables for swap_function to swap it for the asp equivalent,
global $firstletters;
$firstletters.=$php_file[$position];
  global $php_functions;
  global $asp_functions;
global $matchedfunctions;
  global $asp_endings;
  global $php_file;
  global $asp_file;
  global $failure;
  global $parts;
  global $match;
  global $bracketstack;
  $match=0;
//echo '<p>looking for a function to swap for '.substr($php_file,$position,10).'...';
// is this with in our block??
  //if ($php_file[$position]!='?'){
    for ($i=1; $i<count($php_functions)+1; $i++){
  //echo '<br>trying '.$php_functions[$i];
      $n=$position;
      $fn=0;
      $failed=0;
      $overflow=0;
      $match=0;
      while (!$failed && !$match){
  //echo $n.','.$fn.'<br>';
        if($php_file[$n]==$php_functions[$i][$fn] OR strtolower($php_file[$n])==$php_functions[$i][$fn]){
          $n++;
          $fn++;
          //echo '<b>'.$php_file[$n].'</b>='.$php_functions[$i][$fn];
        }else{
          // (each space can be taken to be zero or more spaces)
          if (white_space($php_file[$n]) && $php_functions[$i][$fn-1]==' '){
            //echo 'whitespace in php file'.$php_file[$n].'<br>';
            $n++;
          }elseif(white_space($php_functions[$i][$fn])){
            //echo 'whitespace in php functions'.$php_functions[$i][$fn].'<br>';
            $fn++;
          }elseif($php_functions[$i][$fn]=='%'){
  //echo 'on the parts: ';
            // so we're in the parts. %a%, %b%, %X% etc.
            $fn++;
            $part_label=$php_functions[$i][$fn];
            $fn=$fn+2;
            while($php_functions[$i][$fn]==' ')
              $fn++;
            $partstart=$n;
            $terminator=$php_functions[$i][$fn];
            $found_terminator=0;
            $inescaped='';
            while(!$found_terminator && $n<strlen($php_file) && !$failed){
              if ($inescaped){
  //echo '<i>'.$php_file[$n].'</i>{'.$inescaped.'}';
                // $inescaped is the character that prevents what we're looking at being relevent (ie "blah blah;")
 
              if ($php_file[$n]==$inescaped[0] && $php_file[$n-1]!='\\'){
                  $inescaped=substr($inescaped,1);
                }
              }else{
  //echo '<b>'.$php_file[$n].'</b>';
 
                if ($php_file[$n]=='"' OR $php_file[$n]=="'")
                  $inescaped=$php_file[$n].$inescaped;
                if ($php_file[$n]=='(')
                  $inescaped=')'.$inescaped;
                if ($php_file[$n]==$terminator){
                  $found_terminator=1;// terminator is actually a seperator -terminates the block ie %a%
  //echo '<br>Found terminator';
                  $fn++;
//echo '<i>'.substr($php_file,$partstart,$n-$partstart).'</i>';
                  $parts[$part_label]=substr($php_file,$partstart,$n-$partstart);
//echo '=<i>'.$parts[$part_label].'</i>';
                }
                if($part_label=='X' && $php_file[$n]==chr(10)){
//echo 'found a carriage return';
                  if ($terminator=='#'){ // # means return.
//echo " and it's the terminator: ".substr($php_file,$partstart,$n-$partstart);
                    $found_terminator=1;
                    $fn++;
                    $n--;
                    //back character added here as this is normally the buffer between functions
                    //echo 'fn='.$fn.'. and strlen='.strlen($php_functions[$i]);
                    $parts[$part_label]=substr($php_file,$partstart,$n-$partstart);    
                  }else{
//echo " and it's not the terminator. Terminator being sought is -$terminator-";
                    $failed=1; // no return in an X
                  }        
                }
 
  //echo $php_file[$n].'{'.ord($php_file[$n]).'}';
              }
              $n++;
           
            }
          }else{
            $failed=1;
  //echo 'simply not the same';
          }
        }
        if ($fn>=strlen($php_functions[$i])){
$matchedfunctions++;
          $match=$i;
          // and put the { on the stack if necessary
          if ($asp_endings[$i]){
            array_push($bracketstack,$asp_endings[$i]);
            //echo 'gonna add '.$asp_endings[$i].' at next }<p>';
          }
echo '.';
          //echo '<br><b>found a match:</b> ('.substr($php_file,$position,$n-$position).')=('.$php_functions[$i].')'.$i.'<p>';
          $i=count($php_functions)+1;// to terminate for loop
        }elseif($n>$endblockposition){

          //echo '<b>end of php block</b>';
          $failed=2;
        }
      }//while
    }//for
  return $n;
}

// ********************************************************************
function flip ($var){
// logical NOT
  if ($var)
  $var=0;
  else
  $var=1;
return $var;
}
// ********************************************************************

function validvar ($char){
  // returns true if $char is valid in a variable (or function) name ie is alpha or _
  if (ord($char)>64 && ord($char)<91 )
  $valid=1;
  if (ord($char)>96 && ord($char)<123 )
  $valid=1;
  if ($char=='_')
  $valid=1;
  return $valid;
}
// ********************************************************************

function swap_function ($start,$end){
// swap fundtions found by find_function using global variables below
  global $php_functions;
  global $asp_functions;
global $matchedfunctions;
  global $bracketstack;
  global $php_file;
  global $asp_file;
  global $asp_endings;
  global $failure;
  global $parts;
  global $match;

  $function_count=0; // function count counts functions in order to deal with nested brackets

  $fn_end=find_function ($start,$end);
  $n=$start;
  //echo 'going through swap. '.count($partkeys).' parts';
    if ($match){
      add_code_at_top($match);
      $thefunction=$asp_functions[$match];
      //echo 'Match found!';;
      $partkeys=array_keys($parts);
      //$parts;
      for ($i=0; $i<count($partkeys); $i++){
//echo '<br><b>on</b> '.$parts[$partkeys[$i]].'which has '.strlen($parts[$partkeys[$i]]).' characters';
        //update partkeys - magic quotes, mark other functions for translation, etc.
        for ($ip=0; $ip<strlen($parts[$partkeys[$i]]); $ip++){
  //echo '<br>On part: <b>'.$parts[$partkeys[$i]].'</b><br>';
        //echo $parts[$partkeys[$i]][$ip];
        if ($partkeys[$i]!='X'){
          if ($parts[$partkeys[$i]][$ip]=='"'){
            // DOUBLE QUOTES
            if($insingle){
              $parts[$partkeys[$i]]=substr($parts[$partkeys[$i]],0,$ip).'"'.substr($parts[$partkeys[$i]],$ip);
              $ip++; // cos just added in a double quote to escape
            }elseif ($parts[$partkeys[$i]][$ip-1]==chr(92)){
              $parts[$partkeys[$i]][$ip-1]='"';
            }else{
              $indouble=flip($indouble);
            }
          }elseif ($parts[$partkeys[$i]][$ip]=="'"){
//echo 'In single quotes';
            // SINGLE QUOTES
            if ($parts[$partkeys[$i]][$ip-1]==chr(92)){
//echo 'ESCAPE FOUND('.substr($parts[$partkeys[$i]],$ip-2,3).')';

              $parts[$partkeys[$i]]=substr($parts[$partkeys[$i]],0,$ip-1).substr($parts[$partkeys[$i]],$ip);
            }else{
//echo 'No escape found('.substr($parts[$partkeys[$i]],$ip-2,3).')';
              $parts[$partkeys[$i]][$ip]='"';
              $insingle=flip($insingle);
            }
          }elseif ($parts[$partkeys[$i]][$ip]=="."){
            // STRING CONCOTANATION
            if(!$insingle && !$indouble){
              //$parts[$partkeys[$i]][$ip]="&";
              $parts[$partkeys[$i]]=substr($parts[$partkeys[$i]],0,$ip).' & '.substr($parts[$partkeys[$i]],$ip+1);
              $ip=$ip+2;
            }
           

          }elseif ($parts[$partkeys[$i]][$ip]=="$" && $indouble && validvar($parts[$partkeys[$i]][$ip+1])){
            // MAGIC QUOTES
            // acceptable characters for a variable
            $varname='$';
            $startvar=$ip;
            $ip++;
            while (validvar($parts[$partkeys[$i]][$ip])&& $ip<strlen($parts[$partkeys[$i]])){
              $varname.=$parts[$partkeys[$i]][$ip];
              $ip++;
            }
            if ($parts[$partkeys[$i]][$ip]=='['){
              $brackets=0;
              while (!$endofsquarebrackets && $ip<strlen($parts[$partkeys[$i]])){
                if($parts[$partkeys[$i]][$ip]=='[')
                  $brackets++;
                if($parts[$partkeys[$i]][$ip]==']')
                  $brackets--;
                $varname.=$parts[$partkeys[$i]][$ip];
                if (!$brackets && $parts[$partkeys[$i]][$ip+1]!='[')
                  $endofsquarebrackets=1;
                $ip++;
              }
            }
            $ip++;
            $parts[$partkeys[$i]]=substr($parts[$partkeys[$i]],0,$startvar).'" & '.$varname.' & "'.substr($parts[$partkeys[$i]],$ip-1);
 
          }elseif ($parts[$partkeys[$i]][$ip]=='$' && !$insingle && !$indouble){
            // Skip to the end of any VARIABLES, so as not to confuse them with functions
            $ip++;
            while (validvar($parts[$partkeys[$i]][$ip]) && $ip<strlen($parts[$partkeys[$i]])){
              $ip++;
            }
            $ip--;
          }elseif (validvar($parts[$partkeys[$i]][$ip]) && !$insingle && !$indouble){
            // Mark as FUNCTION if we get letters outside quotes
            $parts[$partkeys[$i]]=substr($parts[$partkeys[$i]],0,$ip).'@@@function{{{'.substr($parts[$partkeys[$i]],$ip);      
            $ip=$ip + strlen('@@@function@@@');
            while (validvar($parts[$partkeys[$i]][$ip])&& $ip<strlen($parts[$partkeys[$i]])){
              $ip++;
            }
            //$ip++;
          }
        }
        }
        if (strpos('.'.$thefunction,'%'.$partkeys[$i].'%')){
        $thefunction=str_replace('%'.$partkeys[$i].'%',$parts[$partkeys[$i]],$thefunction);
//echo 'part in function';
        }else{
          $loopend=array_pop($bracketstack);
          $loopend=str_replace('%'.$partkeys[$i].'%',$parts[$partkeys[$i]],$loopend);
          array_push($bracketstack,$loopend);
//echo ' count($bracketstack)='.count($bracketstack);
//echo '<p>$bracketstack['.$thisloop.']='.$loopend.'</p>';
        }
      $parts[$partkeys[$i]]=''; // unset it
      }
//echo "<br><b>XXX: $thefunction</b> $matchedfunctions matched. Now at $fn_end";

        $asp_file.=$thefunction;
  $asp_file.=chr(10);
//echo htmlentities($asp_file);
    }elseif ($php_file[$start]=='}'){
//echo "ADDING ENDING }";
    $fn_end=$start+1;
    $asp_file.=array_pop($bracketstack).chr(10);
  }elseif ($failed<2 && $php_file[$fn_end]!='?') {

      while (validvar($php_file[$fn_end]))
      $fn_end++;
      //$n=findend($end,$n);
  $chars=$fn_end-$start+1;
      $asp_file.=substr($php_file,$start,$chars);
      $failure[]=substr($php_file,$start,$chars);
    }
  //}
 
  return $fn_end; // where the next statement picks up from
}



// ********************************************************************



function find_php(){

  global $php_file;
  global $asp_file;
$i=0;
  while($i<strlen($php_file)){
  // do we bother translating it or not? - (include also <?php etc)
    if ($php_file[$i]=='?' && $php_file[$i-1]=='<'){
    $php=1;
    $asp_file.='%
'; // the other < will already be there
    $i++;
    }elseif ($php_file[$i]=='>' && $php_file[$i-1]=='?'){
//echo 'DID IT UP HERE';
    $php=0;
    //$asp_file=substr($asp_file,0,-2).chr(10).'%>';
    $asp_file.=chr(10).'%>';
    $i++;
    }
    if ($php){
      while (white_space($php_file[$i])) { // get to end of white space
      $i++;
      }
      $end=$i;
      $foundend=0;
      while (!$foundend) { // get to end of php block
        $end++;
        if ($php_file[$end]=='>' && $php_file[$end-1]=='?')
          $foundend=1;
        if ($end>strlen($php_file))
          $foundend=1;
      }
      $i=swap_function ($i,$end);
//echo 'Gone to swap_function<p>';
//echo '1:<br>'.htmlentities($asp_file);
/*
      if ($i>=$end){
//echo '3:<br>'.htmlentities($asp_file);
        // it remains a mystery how it went past the end, but it did, and this puts it right.
echo 'gone past the end by '.substr($php_file,$i,$end-$i).'('.$end-$i.'characters';
        $asp_file=substr($asp_file,0,$end-1).chr(10).'%>';
//echo '4:<br>'.htmlentities($asp_file);
        $i=$end;
        $php=0;
      }
*/
    }else{
    $asp_file.=$php_file[$i];
    }
  $i++;
  }
}

// **************************************************************

function findcompoundfunctions(){
echo $php_file;
  global $php_functions;
  global $asp_functions;
  global $bracketstack;
  global $asp_endings;
  global $php_file;
  global $asp_file;
  global $failure;
  global $parts;
  global $match;
global $failed;
  while ($x=strpos($php_file,'@@@function{{{')){

//echo '<p>with @@@ etc:'.htmlentities($php_file);
    $php_file=substr($php_file,0,$x).substr($php_file,$x+strlen('@@@function{{{'));
//     echo '<p>without @@@ etc:'.htmlentities($php_file);

    $fn_end=find_function ($x,strlen($php_file));

// ******** copied from swap_function ********
  if ($match){
    $thefunction=$asp_functions[$match];
    //echo '2nd pass Match found!';
    $partkeys=array_keys($parts);
    for ($i=0; $i<count($partkeys); $i++){
      $thefunction=str_replace('%'.$partkeys[$i].'%',$parts[$partkeys[$i]],$thefunction);
    }
    $php_file=substr($php_file,0,$x).$thefunction.substr($php_file,$fn_end);
    add_code_at_top($match);
//echo $match.':'.$thefunction.':';
  }elseif ($failed<2) {
    $failure[]=substr($php_file,$start,$n-$start);
  }
// ********** end of copied from swap_function ********

  }
}



// **********************************************************
function findfunctionname($position){
  global $asp_file,$fn_name_list;
  $lookingfor='Function fn_';
  $length=strlen($lookingfor);
  $n=$position;
  while (!$found && $n>0){
    if (substr($asp_file,$n,$length)==$lookingfor)
      $found=$n;
    $n--;
  }
  $found=$found+$length;
  while (white_space($asp_file[$found]))
    $found++;
  $fn_length=0;
  while (validvar($asp_file[$found+$fn_length]))
    $fn_length++;
  $name=substr($asp_file,$found,$fn_length);
  $fn_name_list.=','.$name;
  return 'fn_'.$name;
}

// **********************************************************

function doreturns(){
  global $asp_file;
  // find $var_the_function_name
  while ($pos=strpos($asp_file,'$var_the_function_name')){
  $markerlength=strlen('$var_the_function_name');
  $name=findfunctionname($pos);
  $asp_file=substr($asp_file,0,$pos).$name.substr($asp_file,$pos+$markerlength);
}
}

// **********************************************************
function unique($string){
  // takes a comma seperated list, and returns a unique one with no blanks
  $string=substr($string,1);
  $str_array=explode(',',$string);
  $string=implode(',',array_unique($str_array));
  return $string;
}

// **********************************************************
function tracevars(){
  global $asp_file,$asp_top_code;
  //printout($asp_file);
  $defined='';
  $i=0;
  while($i<strlen($asp_file)){
  // do we bother translating it or not? - (include also <?php etc)
    if ($asp_file[$i]=='%' && $asp_file[$i-1]=='<'){
    $asp=1;
    }elseif ($asp_file[$i]=='>' && $asp_file[$i-1]=='%'){
    $asp=0;
    $i++;
    }
  // if it's in quotes, also leave it alone
    if ($asp_file[$i]=='"'){
      if (!$inquotes)
      $inquotes=1;
      elseif($asp_file[$i+1]!='"')
      $inquotes=0;
      else{
        // multi " - get to end and work out what we're doing
        $noquotes=1;
        $i++;
        while($asp_file[$i]=='"'){
        $noquotes=$noquotes*-1;
        $i++;
        }
        if ($noquotes>0)
        $inquotes=1;
      }
    }elseif ($asp_file[$i]==chr(10) && $asp){
//echo "<br>".substr($asp_file,$i,12).'...';
      while(white_space($asp_file[$i]))
      $i++;
//echo '&lt;'.substr($asp_file,$i,8).'&gt; ';
      if (substr($asp_file,$i,9)=='Function '){
        $infunction=1;
        $local_vars="";
        $global_list=" ";// not blank so strpos>0
        // Get global variable list if there is one! (maybe global x, y; global z; - ie spread on multiple lines, or not
//       //}elseif (substr($asp_file,$i,1)=='E'){
      }elseif (substr($asp_file,$i,12)=='End Function'){

echo 'found end of function';
        $infunction=0;
        $local_vars=unique($local_vars);
        $local_vars='lv_'.str_replace(',',', lv_',$local_vars);
        $asp_file=substr($asp_file,0,$globalstart)."Dim $local_vars ".substr($asp_file,$globalstart);
        $i=$i+12+strlen("Dim $local_vars ");
      }elseif ($infunction && substr($asp_file,$i,13)=='Global_vars {'){
        $globalstart=$i;
        $i=$i+13;
        while ($asp_file[$i]!='}')
          $i++;
        $nochars=$i-$globalstart-13;
        $global_list.=','.str_replace(' ','',substr($asp_file,$globalstart+13,$nochars)).',';
        $asp_file=substr($asp_file,0,$globalstart).substr($asp_file,$i+1);
        $i=$globalstart-1;
      }
     
    }
  // so worked out wether or not we need to count this variable
    if ($asp && !$inquotes){
      if($asp_file[$i]=='$'){
//echo 'variable found';
        // so it's a variable - find the name
        $i++;
        $start=$i;
        while(validvar($asp_file[$i]))
          $i++;
        $varname=substr($asp_file,$start,$i-$start);
//$n=$i-$start;
//echo '<br>-'.$varname.'-'.$start.'('.$asp_file[$start].'),'.$n.' blah2 <br>';
        while(white_space($asp_file[$i]))
        $i++;
       
        if($asp_file[$i]=='['){
          //so it's an array
//echo 'an array';
          while($asp_file[$i]=='['){
            $asp_file[$i]='(';
            while ($asp_file[$i]!=']')
              $i++;
            $asp_file[$i]=')';
            while(white_space($asp_file[$i]))
              $i++;
          }
          $array=1;
        }else{
          $array=0;
        }
        if ($asp_file[$i]=='+' OR $asp_file[$i]=='-' OR $asp_file[$i]=='*' OR $asp_file[$i]=='/' OR $asp_file[$i]=='%'){
          $type[$varname]='math';
          //echo ', math';
        }elseif ($asp_file[$i]=='='){
          //echo ', defined';
          $defined.=','.$varname;
          // not right - what if it's just being incremented or something
        }
        if ($array)
        $varname.='()';
        if ($infunction && !strpos($global_list,',$'.$varname.',')){
          $local_vars.=','.$varname;
          $asp_file=substr($asp_file,0,$start-1).'lv_'.substr($asp_file,$start);
          //$i=$i+2;
        }else{
          $global_vars.=','.$varname;
          $asp_file=substr($asp_file,0,$start-1).'gv_'.substr($asp_file,$start);
          //$i=$i+2;
        }

        // if next is =, but not in 'if', while, etc, then set as defined
        // at end ie not in this loop, list the undefineds and ask where they're from
      }

    }
  $i++;
  }
  $global_vars=unique ($global_vars);
  $global_vars='gv_'.str_replace(',',', gv_',$global_vars);
  $asp_top_code='Dim '.$global_vars.$asp_top_code;
}

// **********************************************************


if ($Submit){
$php_file=stripslashes($php_file);

  set_functions();
  //trace_undefined_vars(); // in php they could be from get, post, cookie, etc
  find_php(); // swap php functions for asp equivalents
//echo '2:<br>'.htmlentities($asp_file);
  $original_file=$php_file;
  $php_file=$asp_file;
//echo '<p> the @@\'d file:<br>'.htmlentities($asp_file).'<p>';
  findcompoundfunctions(); // second pass
  $asp_file=$php_file;
  doreturns();
//printout($php_file);
  tracevars();
  if ($asp_file[0]=='<' && $asp_file[1]=='%')
    $asp_file='<%'.chr(10).$asp_top_code.chr(10).substr($asp_file,2);
  else
    $asp_file='<%'.chr(10).$asp_top_code.'%>'.chr(10).$asp_file;
  //change_system_vars(); // all those things like $PHP_SELF
  //dedollarfy(); // remove $ from variable names and change [] to () for arrays
 
  if ($failure){
    echo "<p>Couldn't translate these functions:<br>";
    for ($z=0; $z<count($failure); $z++){
      echo $failure[$z].'<br>';
    }
    echo '<p>';
  }
  echo 'The ASP equivalent of your PHP:<br><textarea name="asp" rows="25" cols="100">'.htmlentities($asp_file).'</textarea>';
 
  //printout($php_file);
//printout($firstletters);

}
//echo '<p>PHP:<textarea name="php_file" rows="15" cols="100">'.$original_file.'</textarea>';

?>
<p>Please Note this is a development version and contains the following
errors:
<p>Function names do not have the fn_ prefix added when they are called
(see <a href="/conversionnotes.htm">notes</a>)<br>
MySQL / SQL commands are not yet translated properly.<br>

</td>
</tr>
<tr>
<td><img src="/shim.gif" width="100" height="1"></td>
<td><img src="/shim.gif" width="600" height="1"></td>
</tr>
</table>
<br>

</BODY>
</HTML>