You are here: Re: php script to filter a text file and extract lines starting with keyword? « PHP Programming Language « IT news, forums, messages
Re: php script to filter a text file and extract lines starting with keyword?

Posted by Nick on 11/24/05 18:01

anne001 wrote:
> Hi
>
> For a class, students are going to run an experiment on line. Each time
> a subject runs, his/her data is appended to one giant text file. Their
> own data set will be just one line starting with the keyword they gave
> as identification.
>
> The faculty does not want the students to be able to download and see
> the giant data file. He wants the students to only download and see the
> data that starts with their own identification tag.
>
> in unix, filtering a file to keep only the line starting with code MCB
> would look something like
> tail -f your_file_name | grep MCB
> from what I read.

<?php

$user = 'MCB'; //get this value from wherever it is you get it

//get datafile as an array of lines
$lines = file('datafile.txt');

// Loop through the lines
foreach ($lines as $line_num => $line)
{
if (strpos($line,$user) === 0) //string found at start of line
echo $line;
}

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация