
$myfile = fopen("web.txt", "r")
echo fgets($myfile)//fgets为读取一行,行本质是段落
fclose($myfile)
<?php$c = getLine('./a.txt', 10) // 读取a.txt文件第10行内容
echo $c
/**
* 获取指定行内容
*
* @param $file 文件路径
* @param $line 行数
* @param $length 指定行返回内容长度
*/
function getLine($file, $line, $length = 4096){
$returnTxt = null // 初始化返回
$i = 1 // 行数
$handle = @fopen($file, "r")
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, $length)
if($line == $i) $returnTxt = $buffer
$i++
}
fclose($handle)
}
return $returnTxt
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)