Log in

View Full Version : viewing source



benslayton
08-18-2006, 03:07 AM
ok I know that there is probally one of these out there just yet to find one. I need a website to go to where you can type in the webaddress and view the source, because I sometimes look at the source to learn about how people do different things at home and school. Unfortnatly at school they have deleted notepad or something on all computers. So does anyone know anysites or a PHP script to do this myself hmmm.

benslayton
08-18-2006, 03:27 AM
well stupid me. Why can't I just use the w3c validator. It has the ability to show the source but I would also like to know of a PHP script also.

jscheuer1
08-18-2006, 03:49 AM
Just paste this into the address bar and hit enter:


javascript:void(document.write('<pre>'+document.getElementsByTagName('html')[0].innerHTML.replace(/</g, '[*')+'<\/pre>'))

You will see the code for the page except that all:

<

symbols will be replaced by:

[*

This will allow you to see the code, without this or some other type of replacement, it would simply reproduce the page itself.

To get back to the page itself, use the browser's back button.

jscheuer1
08-18-2006, 04:09 AM
This would be even better, as it will replace with the &lt; entity:


javascript:void(document.write('<pre>'+document.getElementsByTagName('html')[0].innerHTML.replace(/</g, '&lt;')+'<\/pre>'))

That way the code will look about right. Many things will be stripped though, with either method. Such as the DOCTYPE and all quotation and other marks not required by the browser's parsing engine to interpret the code.

benslayton
08-18-2006, 04:09 AM
hmm ok well good idea. I have been messing around with a script that you can view here http://benslayton.awardspace.com/source.php. But that shows the source for the index.php file in that folder.

here is the code if you want to play with it:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>View Source</title>
<style type="text/css">

body {

background-color: #111111;
font-family: Courier New, Courier, mono;
font-size: 11px;
color: #66CCFF;

}

span {

color: #FFFFFF;

}

.linenumber {

color: #FF9900;

}

em {

color: #666666;

}

h3 {

font-family: Tahoma, Trebuchet MS, Arial;
text-decoration: none;

}

.codelink {

font-family: Tahoma, Trebuchet MS, Arial;
text-decoration: none;
font-size: 10px;
color: #EEEEEE;

}

.codelink:hover {

font-family: Tahoma, Trebuchet MS, Arial;
text-decoration: underline;
font-size: 10px;
color: #66CCFF;

}

</style>
</head>

<body>
<?php

$url = "http://" . $_SERVER[ 'HTTP_HOST' ] . "/" . urldecode( $_GET[ "u" ] );
$lines = file( $url );

?>
<?php

foreach( $lines as $line_num => $line ) {

$line = htmlspecialchars( $line );
$line = str_replace( "&lt;", '<span>&lt;', $line );
$line = str_replace( "&gt;", '&gt;</span>', $line );
$line = str_replace( "&lt;!--", '<em>&lt;!--', $line );
$line = str_replace( "--&gt;", '--&gt;</em>', $line );

echo "" . $line . "<br/>\n";

}

?>
</body>
</html>



Edit: oh yeah I would like a form asking for the url and you type in the address and you click sumbit and you can see it.

Twey
08-18-2006, 04:13 AM
Or, you could use &lt; instead of [*.

/EDIT: Gah, router's so slow that by the time it'd finished POSTing, there were a whole two replies :-\ Someone'll probably have commented on that before this edit gets sent, too.

benslayton
08-18-2006, 05:58 AM
you know what like always I just fixed my own problem. I guess its just a matter of time.:)

jscheuer1
08-18-2006, 06:22 AM
It's a little tricky but, you could make it a bookmark.