Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I echo the whole content of a .html file in PHP?

Tags:

html

php

echo

Is there a way I can echo the whole content of a .html file in PHP?

For example, I have some sample.html file, and I want to echo that filename, so its content should be displayed.

like image 297
Nikola Nastevski Avatar asked Mar 02 '12 20:03

Nikola Nastevski


People also ask

How do you echo inside HTML?

<? php $text ='Click here'; $link = 'http://www.google.com'; echo sprintf(" <a href="%s">%s</a>", $link, $text); ?>

How can I print the contents of a file in PHP?

The file_get_contents function takes the name of the php file and reads the contents of the text file and displays it on the console. get the contents, and echo it out.

Is echo PHP or HTML?

With PHP, there are two basic ways to get output: echo and print . In this tutorial we use echo or print in almost every example.

HOW include HTML code in PHP?

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the PHP. Step 2: Now, we have to place the cursor in any tag of the <body> tag where we want to add the code of PHP. And, then we have to type the start and end tag of PHP.


1 Answers

You should use readfile():

readfile("/path/to/file"); 

This will read the file and send it to the browser in one command. This is essentially the same as:

echo file_get_contents("/path/to/file"); 

except that file_get_contents() may cause the script to crash for large files, while readfile() won't.

like image 187
Frxstrem Avatar answered Oct 10 '22 23:10

Frxstrem