Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从文本文件中获取列和行。php/html_Html_File_Text - Fatal编程技术网

如何从文本文件中获取列和行。php/html

如何从文本文件中获取列和行。php/html,html,file,text,Html,File,Text,如果我有一个名为text.txt的文本文件,在第2列第6行的文本文件中有一个单词“help”,我如何读取该单词并用php/html打印出来?用html是不可能的。您需要使用PHP或其他语言 使用PHP <?php $arr = file ("text.txt"); substr($arr[5],2,4); ?> 或者如果你想找到确切的词 <?php $arr = file ("text.txt"); preg_match('/help/', $arr[5], $match

如果我有一个名为text.txt的文本文件,在第2列第6行的文本文件中有一个单词“help”,我如何读取该单词并用php/html打印出来?

用html是不可能的。您需要使用PHP或其他语言

使用PHP

<?php
$arr = file ("text.txt");
substr($arr[5],2,4);
?>

或者如果你想找到确切的词

<?php
$arr = file ("text.txt");
preg_match('/help/', $arr[5], $matches);
print_r($matches);
?>

需要像下面这样使用php:
只需在html页面中插入php代码。使用数组和字符串操作来完成所需操作。

纯HTML无法完成此操作,您需要一些脚本语言。如果文本文件位于服务器上,则必须使用服务器端语言读取文本文件,然后写入页面。HTML仅用于标记,不能以任何方式访问文件。@brb可以使用js在客户端进行编码,请参见此处:@jtheman是的,AJAX将是处理它的一种方法。谢谢你,Robert,它成功了!