【发布时间】:2019-02-26 09:49:35
【问题描述】:
我只想显示 curl 输出的某些行(例如,第 15-20 行)。如果我将输出写入 txt 文件,我知道如何只输出 1 行。但是如何在不先输出到文本的情况下做到这一点呢?那么我如何选择多行?
如果 $myFile = "/whatever.txt" ,这仅适用于第 22 行。但不使用 curl 变量。
谢谢。
<?php
$handle = curl_init();
$url = "https://finance.yahoo.com/";
// Set the url
curl_setopt($handle, CURLOPT_URL, $url);
// Set the result output to be a string.
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($handle);
curl_close($handle);
//echo $output;
$myFile = "$output";
$lines = file($myFile);//file in to an array
echo $lines[22]; // displays line 23 ?>
【问题讨论】:
-
你可以使用explode函数,使用
\n作为分隔符。然后你可以通过他们的索引得到想要的行。