473,394 Members | 1,726 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,394 software developers and data experts.

Referencing a txt file

Hi,

On receiving input from a user I need to reference it to a text file to see
if that entry is present in the file. Is it possible to do this in php, or
will it need to be done in Javascript? Or is it not possible at all? Each
entry in the text file is on a new line if that makes any difference.

Cheers,

Paul
Feb 22 '06 #1
2 1054
Paul Morrison wrote:
Hi,

Hi
On receiving input from a user I need to reference it to a text file to
see if that entry is present in the file. Is it possible to do this in
php, or will it need to be done in Javascript?
How do you expect Javascript to open a file?
Javascript is crippled for very good reasons when it comes to reading local
files.

Or is it not possible at all?
Yes, it is easy in php.
Try something like this:

On receiving the userinput in php:
// assuming the filed is named 'username'
$passedusername = $_POST["username"];

// open your file:
$filecontentes = file('/home/usr/paul/myfile.txt');

// assuming your file contained usernames
if (in_array($passedusername,$filecontents)){
// found it
} else {
/ not found it
}

Each entry in the text file is on a new line if that makes any difference.
of course that makes a difference. :P
If you just search the file for the username (substringsearch) you will get
matches for username A while in your file is Andre.
You don't want that, so match them per line.
Go to www.php.net for details on the functions.

Regards,
Erwin Moller

Cheers,

Paul


Feb 22 '06 #2
Paul Morrison wrote:
Hi,

On receiving input from a user I need to reference it to a text file to see
if that entry is present in the file. Is it possible to do this in php, or
will it need to be done in Javascript? Or is it not possible at all? Each
entry in the text file is on a new line if that makes any difference.

Cheers,

Paul


Using that method typically will not scale - especially if you are expecting new
entries in the file AND reading the file concurrently. You may want to consider
using a database (Oracle, SQLServer,MySQL).

There are various ways to do what you want, just remember, the larger the file
the longer it will take each "hit" to process (which is why you design a
database with proper indexing and a whole lot more)

read the entire file into an array and process through the array until 1) you
get to the end (no records found) or 2)you locate the requested record.
Depending on file size, this may be all you need.

you can use a system call to "grep" or "find" the requested entry - more
difficult to code, but can be faster if the file is very large.

When doing these sorts of things, just remember reading a 1MB file into an array
takes ~1MB+ of physical memory just for the one file. And depending on the
number of page hits, you could potentially be running a memory starved system
which equals poor performance - Use a database engine.

--
Michael Austin.
DBA Consultant
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Feb 22 '06 #3

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

Similar topics

1
by: student | last post by:
while compiling on: SunOS 5.8 Generic_108528-27 sun4u sparc SUNW,Sun-Fire-280R I get the following error: Undefined first referenced symbol ...
11
by: Milind | last post by:
Hi, I was trying to implement a composition relation, somthing of the following type: class A { public: class B {
12
by: Mark Broadbent | last post by:
Hi guys, just going through remoting at the moment and a couple of questions relating to .net in general has surfaced. Firstly I have seen in the designer that for the namespace and many of its...
1
by: Sasha Nikolic | last post by:
I have defined a managed class ( __gc ) and a unmanaged ( __nogc ) in a separate files (but in the same vc++ dotnet project). I have no problem of referencing the unmanaged class from the menaged...
6
by: Mikey_Doc | last post by:
Hi We are running cms 2002, Framework 1.0 with Visual studio 2002. We have just upgraded to Framework 1.1 and visual studio 2003. All of our database connection strings are stored within the...
4
by: TWEB | last post by:
I think I may have an IIS / ASP.Net Configuration issue that I need some guidance with resolving. Here's the problem: a) I have a .stm file. b) I referenc a .aspx file on this .stm file using a...
9
by: Brett Romero | last post by:
Say I have a library (A.dll) with a method that accepts a collection of a specific type. The type is defined in B.dll. In A.dll, I need to loop through this collection and reference fields of...
1
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been...
2
by: Andrus | last post by:
I need compile in-memory assembly which references to other in-memory assembly. Compiling second assembly fails with error Line: 0 - Metadata file 'eed7li9m, Version=0.0.0.0, Culture=neutral,...
1
by: Tom | last post by:
My unsigned DLL works in my project that references it as long as I set Copy Local = true. Now I have signed the DLL with the sn.exe generated keys but have not yet moved the DLL into the GAC. ...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.