...

View Full Version : how to write a loop for coping all line between two lines from a text file



websoftexpert
09-12-2005, 07:12 PM
Hi

Can any one let me know how to write a loop for coping all line between two lines from a text file.

The start line is

|Websoftexpert | | |


and the end line is


|--------------------------------------------------------------------------------------------------------------------------------|

Any sugesstion or code?

thanks in advance

akash sinha
websoftexpert@yahoo.com
http://akash.biz/

marek_mar
09-12-2005, 09:17 PM
This should work:

<?php
$file = 'file.txt';
$start = '|Websoftexpert | | |';
$end = '|--------------------------------------------------------------------------------------------------------------------------------|';
if(file_exists($file) && is_file($file))
{
$handle = fopen($file, 'r');
$ret = array();
$read = false;
while(!feof($handle))
{
$data = fgets($file);
if(trim($data) != $start)
{
$read = true;
continue;
}
if(trim($data) == $end && $read == true)
{
$read = false;
break;
}
$ret[] = $data;
}
}
var_dump($ret);
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum