我有以下的php文件。当我尝试运行此文件时,没有显示任何内容
<html>
<body>
<?php
$myfile = fopen("1.txt", "a+") or die("Unable to open file!");
echo fgetss($myfile,149,"<td>,</td>");
fclose($myfile);
?>
</body>
我的1. txt文件的第149行是
<td>Mfg of Textile Readymade Garments</td>
答案 0 :(得分:1)
根据文档,fgetss
将读取当前行的length
个字节。所以fgetss($myfile,149,"<td>,</td>")
将在第一行读取149个字节。
你可以尝试(快速和肮脏):
<?php
$myfile = fopen("1.txt", "r") or die("Unable to open file!");
for ($i = 0; $i < 149; $i++) fgets($myfile);
echo fgetss($myfile, 4096, "<td>,</td>");
fclose($myfile);
?>
旁注,您要阅读文件,因此请在a+
来电中将r
替换为fopen
答案 1 :(得分:0)
函数 fgetss()第二个参数通知行中返回的字节数,而不是您想要拾取的特定行。
从文件中获取特定行的一种方法是使用函数:
<?php
function get_line($arq,$linha)
{
$arquivo = file($arq);
$y = $linha - 1;
$x = print $arquivo[$y];
return $x;
}
get_line("1.txt",149);
?>