PHP code to HTML conversion

The following PHP script might be helpful 
to anyone who wishes to publish PHP tutorials or who wishes to publish PHP code 
on a HTML webpage.

Tool Use Instruction:

Copy & Paste your source code (can either be purely PHP, or a HTML file containing PHP) 
in the box below and click on "Convert PHP to HTML button.  You may 
check "Output line numbers" checkbox to output line numbers in the converted 
code.




if(isset($submit_button)){
     $html_out=stripslashes($php_code_input);
     if($line_number_input=='ON'){
          $line=strtok($html_out,"\n");
          $html_out='';
          $line_num=0;
          while($line){
               $line_num++;
               $html_out.="".$line_num." $line\n";
               $line=strtok("\n");
          }
     }
     $html_out=str_replace('<','<',$html_out);
     $html_out=str_replace('>','>',$html_out);
     $html_out=str_replace("\t","     ",$html_out);
     $html_out=str_replace(' ',' ',$html_out);
     $html_out=str_replace("\n",'
',$html_out);
     echo $html_out;
}
?>




Output line 
numbers



  

You will see the converted code in the same box above.  To do 
another conversion, just clear the box, Copy & Paste the code in the box above and hit "Convert 
PHP to HTML" again.

What the script does:

The script simply replaces all the "<" to "<", ">" to ">", 
tabs to 5 spaces, and spaces to 
" "