Php 文件处理没有相应地显示数据
我有下面的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。
<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);
?>