473,786 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10636
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
8729
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, returned the hyperlinked page title, filename, and the body txt (30 preceding and following words) in context with the search word highlighted. Excellent.! See it working at: http://www.ipt.co.za Just search for "firearm"
2
1243
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 maybe you just want to inspect exactly what changes were related to a specific bugdb issue. Now I've searched hi and low for this and I now it's out there somewhere bleeding obvious - can't imagine I'm the first to have this thought. I just...
3
9559
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 MusicAlbum let you find MP3 and other music files based on the singer and album name; DocAuthor let you find Office documents created by a certain user; DocAppName let you find files of a particular program, and so on. Indexing Service uses plug-ins...
7
2116
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 lines. and after that save both of those files... since that is a big block of text (15000 lines) i thint that it is a big job to look for a keyword... so my question is this exactly: how do i do this:
1
1684
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 Recipe" in this file. I want to keep everything inbetween these two lines. Below is a small sample of my text file and the code I have so far. 2,3,5,6,56,7,4,7,,,56,5,7, -1,45,4,451,7,66,7,667, "Recipe KX009.RCP, Date=02/11/07, Time=12:20:27,
10
3222
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, TEXT3in entire file(file consisting of 150 lines) that is related to a particular id and get the sum of the, WRITES of TEXT1, TEXT2, TEXT3 ex: input file will be as below Windows 2000 text text text text text text text
4
2937
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 text and I can't find the error on why it isn't working. Any help is greatly appreciated. Here is the form
12
1287
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 community's thoughts/comments on what I've done; improvements I can make, "don'ts" I should be avoiding, etc. I'm not so much bothered about the resulting data - for the moment it meets my needs. But any comment is welcome! #!/usr/bin/env python
1
47489
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10104
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.