简体   繁体   English

使用JavaScript捕获文本文件中的文本

[英]Grabbing text from text files with JavaScript

I have tons of text files from which ones I want to grab the text and display it on one webpage. 我有大量的文本文件,我想从中提取文本并将其显示在一个网页上。 Also I would like to have the file name of those files added at the top of every text grabbed. 我也想将这些文件的文件名添加到每个文本的顶部。

eg: 例如:

file name 文档名称

text from file name 文件名中的文字


file name 文档名称

text from file name 文件名中的文字


... ...

Any idea how can I do this using JavaScript? 知道如何使用JavaScript做到这一点吗?

If is not js I'll be happy with php as well. 如果不是js,我也会对php感到满意。

Thanks :) Vic 谢谢:)维克

have you checked out jquery's load function? 你检查过jQuery的加载功能了吗? i think it will do what you want. 我认为它将满足您的要求。

From client side javascript, you can't do this as you can't get a list of all the text files. 从客户端javascript,您无法执行此操作,因为您无法获取所有文本文件的列表。 It would also be very slow. 这也将非常慢。

For php, see the opendir() function to get the list of files, and the readfile() function to display their contents. 对于php,请参见opendir()函数以获取文件列表,以及readfile()函数以显示其内容。

For PHP it's pretty simple. 对于PHP,这非常简单。

$file = 'path/to/file/';    
$contents = fread($file,'r');
fclose($file);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM