phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP File: Reading File at Particular Lines

Tag: file, read file   Category: PHP Basic
post: 13 Apr 2008 read: 928


PHP File Tips - Part 2: If you want to display or read particular line from file, you can use file(). Just remembering tips part 1, file() will generate array from file reading.

<?
$file = "test.txt";

$f = file($file);

// first line
echo $f[0];
// result test line 1 

echo "<br />";

// end line
echo end($f);
// result test line 3 

echo "<br />";

// second line
echo $f[1];
// result test line 2 

echo "<br />";

// line 2 - 3
$arr = array_slice($f,1,2);
$str = implode(",", $arr);
echo $str;
// result test line 2  test line 3 
?>


Series this article:
PHP File: 3 Way of Reading File
PHP File: Reading File at Particular Lines
PHP File: Reading File at Particular Byte Ranges
PHP File: Checking File or Directory
PHP File: Showing All File in A Directory
PHP File: Showing All Files and Folders in Particular Directory
PHP File: Retrieving File Statistic
PHP File: Retrieving More File Information
PHP File: Counting Lines in a File
PHP File: Counting Characters and Words in File
PHP File: Writing File
PHP File: Locking and Unlocking File
PHP File: Removing Lines From File
PHP File: Inserting Lines into a File

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


619
posting