PHP阅读文本文件 [英] PHP Read Text File
问题描述
嘿,请阅读PHP.net上的一些提示/指针,但似乎无法解决这个问题。\\ b
问题。我有一个读取文件内容的php页面,然后
显示文件的最后XX行。问题是这个...每当
文件变大~5MB时,页面就不会显示任何内容,因为虽然发生超时但是我没有收到任何错误。 4.8MB(最后
确认尺寸)...功能仍然有效。任何想法下面的代码是什么代码
缺乏?
< ;?
$ handle = fopen(" / var / log / myfile"," r");
if($ handle){
while(!feof($ handle)){
$ arrLog [] = fgets($ handle,4096);
}
fclose($ handle);
}
$ int_number_of_lines = count($ arrLog);
if($ int_number_of_lines == 0)
{
echo''< p>< strong>没有读行。< / strong>< / p>'';
}
if($ int_number_of_lines< ; $ int_lines)
{
$ int_lines = $ int_number_of_lines;
}
$ int_firstline = $ int_number_of_lines - $ int_lines;
echo''显示最后一个'。$ int_lines。''排出''。
$ int_number_of_lines。''< BR /> '';
echo"< TABLE WIDTH = 100%CLASS = \" mail \"> \ n";
for($ i = $ int_firstline; $ i< $ int_numb er_of_lines; $ i ++)
{
echo"< TR>< TD>"。$ arrLog [$ i]。"< / TR> < / TD> \ n" ;;
}
echo"< / TABLE> \ n";
?>
handle = fopen(" / var / log / myfile"," r");
if(
handle){
while(!feof(
handle)){
Hey, read some tips/pointers on PHP.net but can''t seem to solve this
problem. I have a php page that reads the contents of a file and then
displays the last XX lines of the file. Problem is this...whenever
the file gets larger that ~5MB, the page just displays nothing, as
though a timeout has occurred but I get no error. At 4.8MB (last
confirmed size)...the function still works. Any ideas what code below
is lacking??
<?
$handle= fopen("/var/log/myfile", "r");
if ($handle) {
while (!feof($handle)) {
$arrLog[] = fgets($handle, 4096);
}
fclose($handle);
}
$int_number_of_lines = count($arrLog);
if ($int_number_of_lines == 0)
{
echo ''<p><strong>No lines read.</strong></p>'';
}
if ($int_number_of_lines < $int_lines)
{
$int_lines = $int_number_of_lines;
}
$int_firstline = $int_number_of_lines - $int_lines;
echo ''Showing the last ''.$int_lines.'' lines out of ''.
$int_number_of_lines.''<BR />'';
echo "<TABLE WIDTH=100% CLASS=\"mail\">\n";
for ($i=$int_firstline; $i<$int_number_of_lines; $i++)
{
echo "<TR><TD>".$arrLog[$i]."</TR></TD>\n";
}
echo "</TABLE>\n";
?>
handle= fopen("/var/log/myfile", "r");
if (
handle) {
while (!feof(
handle)) {
这篇关于PHP阅读文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!