This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Best methods to parse HTML with PHP
I wish to get the code of a website as you can with "view source" but dynamically.
I found a site which does exactly what i want - http://www.iwebtool.com but I wish
to implement it by myself.
any ideas? thanks!
You chould give this a try in a php page:
<html>
<head><title>title</title></head>
<body>
<xmp>
<?php echo file_get_contents('http://www.google.com'); ?>
</xmp>
</body>
</html>
You could replace 'http://www.google.com' with the value of a variable you can set dynamically.
<xmp> is deprecated also you should take care of html special chars so I'd go with:
<pre>
<?php echo htmlentities( file_get_contents( 'http://www.somewebsite.com/somepage.html' ) ); ?>
</pre>
Related
This question already has answers here:
How to display HTML tags as plain text [duplicate]
(11 answers)
Closed 4 years ago.
<!DOCTYPE html> is not displaying on my site, I have a simple website containing html and php question. When I render questions from database, <!DOCTYPE html> will display as it is in input or textarea but without using input field it will show nothing.
This is the question not displaying html code:
Here I have added in statement:
Use htmlspecialchars or htmlentities before outputting your data from the database.
<?php echo htmlspecialchars($string); ?>
or
<?php echo htmlentities($string); ?>
Reference
PHP Manual - htmlentities
PHP Manual - htmlspecialchars
Encode your content before outputting:
<?= htmlspecialchars($questionContent); ?>
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 5 years ago.
Is it possible, using PHP, to get the current HTML loaded into a browser, as a string in PHP?
In other words, this would be the PHP equivalent of document.documentElement.outerHTML in JavaScript.
The question has probably been asked somewhere here, but I can't seem to find it. If this question has already been asked before, could you please give me link? I'm new here at StackOverflow :P
Yes, You can assign the html data using ob_start and ob_get_contents method
<?php
ob_start();
?>
<html>
<head>
<title>Test</title>
</head>
<body>
Testings
</body>
</html>
<?php
$data = ob_get_contents();
ob_end_clean();
print_r($data);
?>
This question already has answers here:
Is there anyway to have Notepad++ highlight both PHP and HTML at the same time?
(2 answers)
Closed 7 years ago.
<html>
This is file is called "example.php".<br>
<?php print "=== This is printed by a php 'print' statement<br>"; ?>
This text is after the embedded php.
</html>
When either of the html tags, its mate is found, and both are given a distinctive color.
But the php tags don't find their mates, and don't get highlighted. How can I get that behavior?
Save your file in .php extention in notepad ++.
If that does not sort the problem download the latest version of notepad++ from here.
Here : it works see :) -
Let me know if anyother issues :)
This question already has an answer here:
How can we include php tag in html with php echo [closed]
(1 answer)
Closed 10 years ago.
I already post this question before but people always ask unnecessary question. I'm gonna explain it in a simple way.
I HAVE 3 files :
a php file (contains only html, thats important) : We call it X file for the example.
a php file where there's some database query to insert database data on the screen : Y file
a php file (a script that will make some manipulations) : Z file
SO, i want to include Y into X with the script of Z.
In Z, i make a str_replace($text, $new, file_get_contents($file));
The ONLY THING is that i need to include PHP open and close TAGS in X because there's no php tags in it.
So, $new = "<?php include('Y.php'); ?>";.
If you try, the close tag wont be considered in the string, but that's what i want.
Hope this question is NOW clear. I can't be more clearer than that. :D
Thanks for you advice.
You need to replace the < and > characters with their HTML entities:
<?php echo "<?php include('this.php'); ?>"; ?>
If you want to include the file, there's no need for the above, running the code below is more than sufficient:
<?php
include('this.php');
?>
You don't have to use two lots of PHP tags...
I may as well put this as an answer.
If you don't want to manually replace < and >:
<?php echo htmlentities("<?php include('this.php'); ?>"); ?>
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do I get the HTML code of a web page in PHP?
Is there a PHP code to get the HTML code of a webpage?
$html = file_get_contents('https://stackoverflow.com/questions/ask');
this doesnt work. It simply loads the webpage. I want to display the HTML code when I run the code.
Thanks in advance.
Try:
echo htmlentities(file_get_contents('http://stackoverflow.com/questions/ask'));
Just HTML encode your output, so that & becomes &, using the htmlentities function.
Perhaps try:
$html = htmlspecialchars(file_get_contents('http://stackoverflow.com/questions/ask'));
and try using the tags to output it.
$handle = #fopen("'http://www.webmasterworld.com", "rt");
$code = fread($handle,9000);
This is copied form another thread, but it should be good enough. It will get the code in $handle and then $code would contain 9000 bytes of that code.
Try using exec and wget together:
<?php
exec('wget http://stackoverflow.com/questions/ask -O', $array);
echo implode('<br />', $array);
?>