Zend - The PHP Company




Source Viewers

Add Code


View source code in web-browser  

Type: code fragment
Added by: krikon
Entered: 10/07/2000
Last modified: 08/12/1999
Rating: - (fewer than 3 votes)
Views: 12044
This script copy a php source file to a *.phps file and redirect the browser there. phps files are (at least with apache) displayed as code with syntax highlightning.


<?

/******************************************
#  File:  view_source.php
#  Description: Script to view code with highligths.
#                Link to this file with 
#                "view_source.php?source=/mypath/myfile.php"
#                
#                Makes a copy of the php file and names it phps.
#                And then redirects the browser to the new phps file.
#                phps files are automaticly code highlighted and displayed
#                if you are using Apache.
#
#  Author: Krister Konst
#          krister@krikon.com
******************************************/








function source($source
{  
  
clearstatcache();                              // cache of the filething dele. 
  
if(!file_exists($source))                      // Checking for the file $source. 
  

    return 
false
  } 
  


// this returns an array of string of wich the last element is the filename.
$path_arraysplit("/" $source);

$num sizeof($path_array);
$str str_replace ("php""phps"$path_array[$num-1]);


global 
$target_file

// to make this work you must make the source directory first. 
$target_file "./source/" $str;

 
copy($source,$target_file);

      
  return 
true



source($source);

header ("Location: $target_file");                 /* Redirect browser 
                                           to the newly created phps file/
exit;                 /* Make sure that code below does 
                         not get executed when we redirect. */
      




?>


Usage Example


<a href="view_source?source=class/person.class.php">source </a>


Rate This Script





Search



This Category All Categories