当前位置: 动力学知识库 > 问答 > 编程问答 >

PHP FTP Get Last Lines

问题描述:

Hello i have a code she gets the contents of a file to a FTP Server but i dont want all file i need only the last 10 lines of file

My Code

 <?php

...

$conn = ftp_connect($server);

if (@ftp_login($conn, $username, $password)) {

}

else {

echo 'Could not authenticate on FTP server';

}

ftp_pasv($conn, true); /* try it with and without this line to see which works (depends on server) */

ob_start();

ftp_get($conn, 'php://output', $remoteFile, FTP_ASCII);

$data = ob_get_contents();

ob_end_clean();

ftp_close($conn);

$site = $data; // output data

?>

So i need to advence it i tryed reading file with fopen but dont work only this code work for me to read a file in a Remote FTP Server

网友答案:

Split $data into lines with explode(), then get the last 10 elements of the array.

$lines = explode('\n', $data);
$last_10_lines = array_slice($lines, -10);
分享给朋友:
您可能感兴趣的文章:
随机阅读: