Вывод определенных строк вывода curl - PullRequest
0 голосов
/ 22 сентября 2018

Я хотел бы отобразить только определенные строки вывода curl (например, строки 15-20).Я знаю, как вывести только 1 строку, если я записываю вывод в текстовый файл.Но как сделать это без предварительного вывода текста?И как мне выбрать несколько строк?

Если $ myFile = "/whwhat.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 ?>

1 Ответ

0 голосов
/ 22 сентября 2018

Ну, вы не получаете никаких данных от Google Finance, так как он защищен от SSL.Следовательно, вы должны добавить необходимые опции ssl к curl, чтобы получить текст.Смотрите исправленный код.

$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);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
$output=curl_exec($handle);
curl_close($handle);

$myFile = "myfile.txt";
file_put_contents($myFile,$output);

$lines = file($myFile);//file in to an array


echo $lines[114]; // displays line 114 which has some text
...