Home >Backend Development >PHP Problem >How to read text and display it in PHP

How to read text and display it in PHP

藏色散人
藏色散人Original
2019-10-09 09:09:492852browse

How to read text and display it in PHP

How does PHP read text and display it?

Using PHP to read the contents of text files is actually very simple , we only need to master the use of the function "file_get_contents();". Below, the editor will give a detailed introduction.

Introduction to the file_get_content() function.

Definition and usage

The file_get_contents() function reads the entire file into a string.

Same as file(), except that file_get_contents() reads the file into a string.

The file_get_contents() function is the preferred method for reading the contents of a file into a string. If supported by the operating system, memory mapping technology is also used to enhance performance.

Syntax

file_get_contents(path,include_path,context,start,max_length)

Use file_get_contents() to obtain the contents of the txt file. The specific parameter description is as follows:

Specific example description. Read the content from the text file tst.txt and display it in the browser. The specific code is as follows:

<?php
  $file = &#39;tst.txt&#39;;
  $content = file_get_contents($file); //读取文件中的内容
  echo $content;
  ?>

Recommended tutorial: PHP video tutorial

The above is the detailed content of How to read text and display it in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn