How to display source code of the page in PHP

search value increase PHP Execution Time connect multiple database display source code save image Export MySQL Database configure mongodb send email from localhost

I am going to share  How to display source code of the page in PHP.you have created any application and you want to share code on internet and allow to make code view-able on page then you can simply use One very cool function in php called show_source(), with the help this function you can easily display source code of the page with php highlighted syntax. See below example.

Also Read: How to create animated counter number using jquery

Here is example for display source code of the page in PHP

Suppose you have page named helloworld.php

<html> 
<body> 
<?php 
echo ("Hello World"); 
?> 
</body> 
</html>

And you want to display helloworld.php source code on html div then you can simply call show_source() function in php like this.
source.php

<div class="sourcecode">
<?= show_source("helloworld.php")  ?>
</div>

You only need to pass the page name in this function and it’ll return full page code with PHP highlighted syntax.

OutPut will be..

<div class="sourcecode">
<html> 
<body> 
<?php 
echo ("Hello World"); 
?> 
</body> 
</html>
</div>

Leave a Reply