Home >Backend Development >PHP Tutorial >php读取文本限制输出多少条

php读取文本限制输出多少条

WBOY
WBOYOriginal
2016-06-23 14:24:15993browse

$host = file('./aa/host.txt');
$keys = file('./aa/keys.txt');
for($j=count($host)-1;$j>=0;$j--){;
echo '

  • '.trim($keys[$j]).'
  • '.PHP_EOL;
    }
    ?>

    现在是全部输出了 怎么做限制输出多少条 请大侠帮忙完整写下啊

    回复讨论(解决方案)

    把 count($host) 改成你需要的行数

    你的代码是把源文件顺序反转输出的
    for($j= count($host)-1;$j>= 0;$j--)

    改为
    for($j=count($host)-1;$j>= count($host)-n;$j--)
    则输出源文件最 后n行

    改为
    for($j= n-1;$j>=0;$j--)
    则输出源文件最 前n行

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn