Ashish Srivastava
Ashish Srivastava

Reputation: 307

php- how to get specific line from a result?

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?

Upvotes: 2

Views: 2584

Answers (3)

Kiyan
Kiyan

Reputation: 2193

$lines = explode("\n", $result);
echo $lines[16];

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

Upvotes: 0

Alberto
Alberto

Reputation: 672

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.

Upvotes: 0

Thiyagu
Thiyagu

Reputation: 17900

You can use explode. Refer here

$res = explode("\n",$result);
echo $res[16];

Upvotes: 3

Related Questions