开发者

View source of PHP, Javascript, and HTML?

开发者 https://www.devze.com 2023-01-17 10:00 出处:网络
I\'ve got a .php file with javascript, php, and html.I want to include a button/link to view the source of the entire file \"pretty pri开发者_StackOverflownted\", but I can\'t seem to get anything to

I've got a .php file with javascript, php, and html. I want to include a button/link to view the source of the entire file "pretty pri开发者_StackOverflownted", but I can't seem to get anything to work. What is the best way to do this?


Some combinations of Apache/PHP are configured so that files ending in .phps aren't run as PHP, but instead, highlighted and prettified.

Example:

View source of PHP, Javascript, and HTML?


If you simply want to display the code of the file, you can call this function:

function echoFile($pathToFile){

  $handle   = fopen($pathToFile, "r");
  $contents = fread($handle, filesize($pathToFile));
  fclose($handle);
  $contents = str_replace("<", "&lt;", $contents);
  $contents = str_replace(">", "&gt;", $contents);
  echo "<pre>$contents</pre>";
}

So, if you want to display myPhpFile.php, just do

echoFile("myPhpFile.php");

As far as making it prettified, follow the link that was commented.

0

精彩评论

暂无评论...
验证码 换一张
取 消