search
Homephp教程php手册读取文本文件并显示在网页

本文章来讲二种读取文本文件并显示在网页的php实例了,方法很简单,用fopen,加explode,for就实现了。
 代码如下 复制代码
$file = "./text.txt";
$text = fread(fopen($file,"r"),filesize($file));
$line = explode(" ",$text);
echo "";
    for($i = 0; $i  $txt = explode(" ",$line[$i]);
 echo "";
    }
echo "
".$txt[0]." ".$txt[1]." ".$txt[2]." ".$txt[3]."
";

//方法二

 代码如下 复制代码

$content = file_get_contents('test.txt');

$arr = explode(" ", $content);
echo "

";

foreach ($arr as $v) {
$tmp = explode("    ", $v);
echo "

";
echo "";
echo "";
echo "";
echo "";
echo "";
unset($tmp);
}

echo "

" . $tmp[0] . "" . $tmp[1] . "" . $tmp[2] . "" . $tmp[3] . "
";

//其实不有一个方法来实现上的实例,file函数哦,这个我也不说多了。查查就知道了,它读出内容直接保存到数据,就不用我们使用explode函数了。
/*
文本文本格式如下

读取一个文本文件内容如下
1       aaaa    bbba    ccca
2       aaaa    bbbb    cccb
3       aaaa    bbbc    cccc
3       aaaa    bbbc    cccc

 



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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.