Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.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 文件处理没有相应地显示数据_Php_Html - Fatal编程技术网

Php 文件处理没有相应地显示数据

Php 文件处理没有相应地显示数据,php,html,Php,Html,我有下面的php文件。当我尝试运行此文件时,没有显示任何内容 <html> <body> <?php $myfile = fopen("1.txt", "a+") or die("Unable to open file!"); echo fgetss($myfile,149,"<td>,</td>"); fclose($myfile); ?> </body> 我的第149行1。

我有下面的php文件。当我尝试运行此文件时,没有显示任何内容

<html>
<body>
    <?php
    $myfile = fopen("1.txt", "a+") or die("Unable to open file!");
    echo fgetss($myfile,149,"<td>,</td>");
    fclose($myfile);
    ?>
</body>

我的第149行1。txt文件是

<td>Mfg of Textile Readymade Garments</td>
纺织成衣的制造
根据文档,
fgetss
将读取当前行的
长度
字节。因此,
fgetss($myfile,149,“,”)
将在第一行读取149个字节

你可以试试(快速和肮脏):



旁注,您想读取文件,因此在
fopen
调用中,将
a+
替换为
r
函数fgetss()第二个参数通知行中返回的字节数,而不是要拾取的特定行

从文件中获取特定行的一种方法是使用函数:

<?php

function get_line($arq,$linha)
{
 $arquivo = file($arq);
 $y = $linha - 1;
 $x = print $arquivo[$y];
 return $x;
}
get_line("1.txt",149);
?>


文件的扩展名是什么。php pr.html?你想从哪里运行它?你的代码似乎适合我。检查1.txt文件是否具有读写权限,并检查文件路径。
149
是从文件中当前位置读取的字节数。而不是要读取的行号如果您想具体读取第149行,您必须在循环中使用
fgets
读取148行,然后使用
fgetss
读取该行的.php文件,我正在本地wamp服务器中尝试运行该文件
<?php

function get_line($arq,$linha)
{
 $arquivo = file($arq);
 $y = $linha - 1;
 $x = print $arquivo[$y];
 return $x;
}
get_line("1.txt",149);
?>