get html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

get html

Post by SidewinderX »

i was wondering if there was a function to get the html of a site (view the html source). I did it a wile ago...i thought i did it with file_get_contents but that dosnt seem to be working..it just displays the entire site not the source...does anyone have any idea of the function im looking for?

Thanks
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

display the output on an html page are you? If so, then display the page normally it should (being parsed by the browser it is).



look at htmlentities() to convert to a viewable "source" you should.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Hi! Is this what you are looking for?

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  <title>InsideView</title>
</head>

<body>

<?php
$file = $_POST['file'];
$form = "<form  action=\"\" method=\"post\">\n" . 
		"Enter a URL\n" . 
		"<input type=\"text\" name=\"file\" value=\"http://\" tabindex=\"1\" />\n" . 
		"<input id=\"submit\" type=\"submit\" value=\"Look at the source code\" tabindex=\"1\" />\n\n";
if (empty ($file)) {
	print $form;
}else{
	$ok = @($file = file_get_contents ($file));

	if (!$ok) {
	echo "<p>It appears that URL isn't valid! Please try again<br />$form</p>";
	} else {	
	print ('<pre>' . htmlspecialchars ($file) . '</pre>');
	} 
}
?>

</body>
</html>[/php:1:ada3d3etrict.dtd">

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  <title>InsideView</title>
</head>

<body>

<?php
$file = $_POST['file'];
$form = "<form  action=\"\" method=\"post\">\n" . 
		"Enter a URL\n" . 
		"<input type=\"text\" name=\"file\" value=\"http://\" tabindex=\"1\" />\n" . 
		"<input id=\"submit\" type=\"submit\" value=\"Look at the source code\" tabindex=\"1\" />\n\n";
if (empty ($file)) {
	print $form;
}else{
	$ok = @($file = file_get_contents ($file));

	if (!$ok) {
	echo "<p>It appears that URL isn't valid! Please try again<br />$form</p>";
	} else {	
	print ('<pre>' . htmlspecialchars ($file) . '</pre>');
	} 
}
?>

</body>
</html>[/php:1;quote; method=\"post\">\n" . 
		"Enter a URL\n&quote; . 
		&quote;&lt;input type=\&quote;text\&quote; name=\&quote;file\&quote; value=\&quote;http://\&quote; tabindex=\&quote;1\&quote; />\n" . 
		"<input id=\"submit\" type=\"submit\" value=\"Look at the source code\" tabmp;amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  <title>InsideView</title>
</head&gt;

&lt;body&gt;

&lt;?php
$file = $_POST&#1111;'file'];
$form = &quote;&lt;form  action=\&quote;\&quote; method=\&quote;post\&quote;&gt;\n&quote; . 
		&quote;Enter a URL\n&quote; . 
		&quote;&lt;input type=\&quote;text\&quote; name=\&quote;file\&quote; value=\&quote;http://\&quote; tabindex=\&quote;1\&quote; /&gt;\n&quote; . 
		&quote;&lt;input id=\&quote;submit\&quote; type=\&quote;submit\&quote; value=\&quote;Look at the source code\&quote; tabindex=\&quote;1\&quote; /&gt;\n\n&quote;;
if (empty ($file)) {
	pmp;quote;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quote;&gt;

&lt;html lang=&quote;en&quote; xmlns=&quote;http://www.w3.org/1999/xhtml&quote;&gt;
&lt;head&gt;
     &lt;meta http-equiv=&quote;content-type&quote; content=&quote;text/html; charset=iso-8859-1&quote; /&gt;
  &lt;title&gt;InsideView&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;?php
$file = $_POST&#1111;'file'];
$form = &quote;&lt;form  action=\&quote;\&quote; method=\&quote;post\&quote;&gt;\n&quote; . 
		&quote;Enter a URL\n&quote; . 
		&quote;&lt;input type=\&quote;text\&quote; name=\&quote;file\&quote; value=\&quote;http://\&quote; tabindex=\&quote;1\&quote; /&gt;\n&quote; . 
		&quote;&lt;input id=\&quote;submit\&quote; type=\&quote;submit\&quote; value=\&quote;Look at the source code\&quote; tabindex=\&quote;1\&quote; /&gt;\n\n&quote;;
if (empty ($file)) {
	print $form;
}else{
	$ok = @($file = file_get_contents ($file));

	if (!$ok) {
	echo &quote;&lt;p&gt;It appears that URL isn't valid! Please try again&lt;br /&gt;$form&lt;/p&gt;&quote;;
	} else {	
	print ('&lt;pre&gt;' . htmlspecialc<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  <title>InsideView</title>
</head>

<body>

<?php
$file = $_POST['file'];
$form = "<form  action=\"\" method=\"post\">\n" . 
		"Enter a URL\n" . 
		"<input type=\"text\" name=\"file\" value=\"http://\" tabindex=\"1\" />\n" . 
		"<input id=\"submit\" type=\"submit\" value=\"Look at the source code\" tabindex=\"1\" />\n\n";
if (empty ($file)) {
	print $form;
}else{
	$ok = @($file = file_get_contents ($file));

	if (!$ok) {
	echo "<p>It appears that URL isn't valid! Please try again<br />$form</p>";
	} else {	
	print ('<pre>' . htmlspecialchars ($file) . '</pre>');
	} 
}
?>

</body>
</html>
Post Reply