2

I want to get the line number 17 of some text using php. My code is as:

$result = curl_exec($ch); //stores text

Now a large number of text is stored in $result & I want to get its line 17. How can I do that?

violator667
  • 469
  • 4
  • 19
Ashish Srivastava
  • 167
  • 1
  • 1
  • 10
  • If you want to consider performance, look at http://stackoverflow.com/questions/1462720/iterate-over-each-line-in-a-string-in-php. – Amit Jan 16 '15 at 09:03

3 Answers3

3

You can use explode. Refer here

$res = explode("\n",$result);
echo $res[16];
Thiyagu
  • 17,362
  • 5
  • 42
  • 79
0

Find the line separator echoing the returned data from curl_exec(), then write the 17th array's element.

$res = curl_Exec($ch);
$res = explode("\n",$res);
echo $res[16]; // array starts from 0, so 16th is your 17th line.
Alberto
  • 674
  • 13
  • 25
0
$lines = explode("\n", $result);
echo $lines[16];

but base on your result you may have to use "\r\n" Instead of "\n"

Kiyan
  • 2,155
  • 15
  • 15