Click to See Complete Forum and Search --> : flatfile/text databases


tiggerific
03-20-2004, 03:43 AM
Hi guys. I know this is an easy thing to achieve, but I have absolutely no idea which of the many file and db functions I need to use to perform the task.

All I need to be able to do is get the username (who is already logged in and the $_SERVER[PHP_AUTH_USER] variable works fine).

Once I've got the username, I want to open a text database file (file.db), locate the row that contains the username in the third column/field and return that row's email address in field 2 to be saved to a variable.

The database file is actually generated by a cgi member's script and it uses the pipe | character as the separator and physical line breaks as the line end.

A nice simple solution would really make my day :) or night ;)

Thanks.

simpson97
03-20-2004, 04:27 AM
Maybe this might help:
It is untested but should work

PHP:

<?php
$username = 'john doe';
$db_array = file('your_db_name.ext');
for($i = 0; $i < count($db_array); $i++)
{
$line = $db_array[$i];
$lineArr = explode("|", $line);
if($username == $lineArr[3])
{
$email = $lineArr[2];
break;
}
}
?>

Bob

tiggerific
03-20-2004, 05:34 AM
a little bit of code reshuffling and I got it working :)

Thanks very much for your help.