Display source code of the website with PHP

Display source code of the website with PHP

Right now, will figure out how to erase a component from a cluster in PHP? There are 2 different ways of erasing a component from the cluster in PHP which is utilizing disconnected() and array_splice().

PHP is a server-side scripting language and gives a dynamic substance to the website pages. It fabricates the source code for the site page that is then parsed by the program to render the site page. Be that as it may, we can likewise discover the source code of a site page with PHP and right now; will figure out how to show the source code of the site with PHP?

Following is the code that will be clarified after the program,

Code

<?php 
// display source code

// get the url as file
$lines = file('http://google.com/');

//Loop each line as line_num
foreach ($lines as $line_num => $line) {
	
	// loop through each line and prepend line numbers and echo it
	echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
?>

Right off the bat, we have the $lines variable which will keep the consequence of the source code created by the document() worked in technique for PHP. The documented strategy just takes a URL and produces the source code record of it. This is then kept as an exhibiting line by line and put away inside the lines variable which we can use to show the source code line by line.

To do that, we have to run a circle on this exhibit and reverberation a line number alongside one line. This can be accomplished utilizing the forEach circle which takes every component of a cluster $lines as $line_num related with $line. We at that point reverberation out the line number in striking utilizing the HTML labels in the middle of since this page is sent by server lastly rendered on the program. We utilize the htmlspecialchars() so as to securely show the HTML labels.

This program causes us to show the source code of a URL line by line to the client? On the off chance that you like the article, if it’s not too much trouble share your musings in the remarks beneath.

Recent Posts

error: Alert: Content is protected!!