Menu
I am in the process of writing a script to grab the HTML source code of a page when the address is passed to it.
I figured I should use the include function to grab the page but how to set the function to contain a variable, or how to get it to print the variables as text, or even better, in a text box, I wasn’t 100% sure.
Any ideas/suggestions on what I could do, what functions to use would be more than welcome.
I thought htmlspecialchars() would be the right one to use but other than that Im not sure how to put it all together…
[code=php]
<?php
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$new = htmlspecialchars($handle);
echo $new;
?>
[/code]
[code=php]<?php
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while(!feof($handle))
{
$contents .= fread($handle, 8192);
}
fclose($handle);
echo htmlspecialchars($content);
?>[/code]
[code=php]
<?php
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while(!feof($handle))
{
$contents .= fread($handle, 8192);
}
fclose($handle);
echo htmlspecialchars($content);
?>
[/code]
[code=php]<?PHP
$source = file_get_contents('http://www.w3.org/');
echo $source;
?>[/code]
[code=php]
<?PHP
$source = file_get_contents('http://www.w3.org');
echo htmlspecialchars($source);
?>
[/code]
[code=php]
<?PHP
$source = file_get_contents('http://www.w3.org');
$readit = htmlspecialchars($source);
echo nl2br($readit);
?>
[/code]
Now to start working out how to colour code it all....[/quote]Surely the various PHP syntax-highlighting functions highlight HTML regardless of whether there's any PHP in there?
[code=php]<div><a href="http://www.google.com">Test Link</a></div>[/code]
[code=php]
<?PHP
$source = file_get_contents('http://www.w3.org');
echo highlight_string($source);
?>
[/code]
[code=php]
// returns a string that can be usually used to display the source of the calling script
// NOTE: Does not print the code, just returns it.
function source_code()
{
$url = $_SERVER['PHP_SELF'];
$loops = times_string_appears($_SERVER['PHP_SELF'], "/") - 1;
for($j = 0; $j ‹ $loops; $j++)
$url = "../" . $url;
$contents = file_get_contents($url); // raw contents
$contents = str_replace("‹", "‹", $contents); // replace the ‹
$contents = str_replace("›", "›", $contents); // replace the ›
$contents = str_replace("t", " ", $contents); // replace the tab character
$contents = nl2br($contents) . "‹br /›"; // make new lines ‹br›'s
return $contents;
}
[/code]
..........???
[code=php]
<?PHP
$file = file_get_contents("index.php");
$file = "<?" . $file;
$file_source = highlight_string($file, 1);
echo(substr_replace($file_source, '', 51, 5));
?>
[/code]
[code=php]
<?PHP
if(isset($_POST['urlinput'])) {
$source = file_get_contents($_POST['urlinput']);
$output = htmlspecialchars($source);
if($_POST['linewrap'] == '1') {
//linewrap and PHP colour code
$source = "<?" . $source;
$file_source = highlight_string($source, 1);
echo(substr_replace($file_source, '', 51, 5));
} else {
//as it is in the text
echo "<pre>n $output n</pre>";
}
}
else{
// show form
$html .= "
<form action='$self' method='post'>
<input type='text' name='urlinput' />
<input type='radio' name='linewrap' value='1' checked /><br />
<input type='radio' name='linewrap' value='0' /><br /><br />
<input type='submit' name='Submit' value='Submit' />
</form>";
echo $html;
}
?>
[/code]
0.1.9 — BETA 5.21