在PHP中打开多个文件 [英] fopen multiple files in php
本文介绍了在PHP中打开多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图使我的PHP脚本打开多个文本文档并阅读它们.
I'm trying to make my PHP script open more than 1 text document and to read them.
我当前的脚本如下:
<?php
//$searchthis = "ignore this";
$matches = array();
$FileW = fopen('result.txt', 'w');
$handle = @fopen("textfile1.txt", "r");
ini_set('memory_limit', '-1');
if ($handle)
{
while (!feof($handle))
{
$buffer = fgets($handle);
if(stripos($buffer, $_POST["search"]) !== FALSE)
$matches[] = $buffer;
}
fwrite($FileW, print_r($matches, TRUE));
fclose($handle);
}
?>
我正在尝试像一堆文件一样打开文件,也许不超过8个文件.
I'm trying to fopen like a bunch of files, maybe like 8 of them or less.
我将如何打开并读取所有这些文件?
How would I open, and read all these files?
我们非常感谢您的帮助!
Any help is GREATLY appreciated!
推荐答案
php中有一个名为file
的函数,它将整个文件读入数组.
There is a function in php called file
which reads entire file into an array.
<?php
// "file" function creates array with each line being 1 value to an array
$fileOne = file('fileOne.txt');
$fileTwo = file('fileTwo.txt');
// Print an array or do all array magic with $fileOne and $fileTwo
foreach($fileOne as $fo) {
echo $fo;
}
foreach($fileTwo as $ft) {
$echo $ft;
}
?>
详细了解以下内容:文件函数ion php
Read more about : file function ion php
这篇关于在PHP中打开多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文