473,388 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

php script to filter a text file and extract lines starting with keyword?

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.

Given the concerns the faculty has for protecting the database, what do
I need to look into to write a php script that would access the data
file, but only show a web page with the data corresponding to the
students identification code?

thanks for some direction, php functions, php keywords I need to look
into.
Anne

Nov 24 '05 #1
4 10568
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;
}

?>
Nov 24 '05 #2
Thank you very much.

It just occured to me that the faculty's request to keep the raw data
off limit may just not be possible: Any student can read the php code,
find the address of the
raw file, and download all of it.

It seems to me his TA will have to run the script once a day to a file,
which the students will in turn access with your little script.

I was running through the tutorial
http://www.macdevcenter.com/pub/a/ma...30/apache.html
to set php up -- which the students will have to do also.

I also like to turn Off the allow_url_fopen feature, though this is
more cautious paranoia than any tried-and-true trick. This setting
allows the PHP fopen function to load remote documents stored on other
web servers, and has been implicated in a number of break-ins with
poorly designed applications. Turn it Off for now, and if you ever need
to use it in the future, you'll probably be smart enough to make a more
informed decision.

If we turn off allow_url_fopen, will file work?
Anne

Nov 24 '05 #3
anne001 wrote:
Thank you very much.

It just occured to me that the faculty's request to keep the raw data
off limit may just not be possible: Any student can read the php code,
find the address of the
raw file, and download all of it.

It seems to me his TA will have to run the script once a day to a file,
which the students will in turn access with your little script.

I was running through the tutorial
http://www.macdevcenter.com/pub/a/ma...30/apache.html
to set php up -- which the students will have to do also.
Are the students accessing this through a browser? If so then they won't
be able to read the PHP source code, and the raw file doesn't need to
be accessible to them, only by the script.

To do this you will probably want to move the raw file so it's not under
the web directory, and then access it as file('../file.txt') or whatever
the path would be then. That way they can't get to the file.

If they're running PHP directly as a command-line script, then you will
just have to make sure that the raw file permissions make it unreadable
to the students, but readable to PHP (which has default user 'nobody',
I think).
If we turn off allow_url_fopen, will file work?


Yes, that only applies to opening files from remote http:// locations,
in my example it was a local file.
Nov 24 '05 #4
Thank you so much for taking the time to help me, your script worked
just fine for the class.

thank you

Dec 8 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
2
by: Holger | last post by:
I needed a tool for extracting patches from CVS based on the log messages. I.e. we mark our fixes and features with a "Bugdb XYZ" And sometimes you need to move a fix/feature to another branch or...
3
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
7
by: peraklo | last post by:
Hello, there is another problem i am facing. i have a text file which is about 15000 lines big. i have to cut the last 27 lines from that file and create a new text file that contans those 27...
1
by: Quentin | last post by:
First off, I would like to thank those who have given me help so far! I would like to remove all the lines of data above the word Recipe in a text file and all the lines below the words "End of...
10
by: bluemountain | last post by:
Hi there, Iam new to python forms and programming too I had a text file where i need to extract few words of data from the header(which is of 3 lines) and search for the keyword TEXT1, TEXT2,...
4
cassbiz
by: cassbiz | last post by:
Could use some help here. This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working???? from the form I want to carry over two lines of...
12
by: Phillip B Oldham | last post by:
I'm keen on learning python, with a heavy lean on doing things the "pythonic" way, so threw the following script together in a few hours as a first-attempt in programming python. I'd like the...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.