Forum Moderators: coopster
While scripting PHP I encountered the following problem.
I'm using a flat text file to store the style preferences of each user. So they can choose their own style, it's stored in a text file (./data/customize.dat) and it looks like this for example:
username¦FF00FF¦FFFF00¦00FF00
anotheruser¦FF00FF¦FFFFFF¦00FF00
yetanother¦CC0000¦FF0000¦0000F0
As you can see, the 3 last items are parts of hexadecimal colors. Well, I've got the username in a cookie and I want to use the colors in my script like this:
$color[1], $color[2], ...
I know how to open a file and make loop, but I don't know how to check which row I have to use, according the username. This is what I've got so far (it's part of a function).
$results = file ($_SERVER["DOCUMENT_ROOT"] . "/tn_v32/lib/data/customize.dat");
if (!$results) {
return '/* ERROR OCCURED WHILE OPENING USERFILE */';
}for($i = 0; $i < count($results); $i++) {
// what to do in here? :S
return $color;
}
Does anybody know how I can reach this using PHP?
for($i = 0; $i < count($results); $i++) {
$user_array = explode("¦",$results[$i]);
if ($user_array[0] == $_SESSION["username"]){
$color[1] = $user_array[1];
$color[2] = $user_array[2];
$color[3] = $user_array[3];
}
return $color;
}
Confused yet? I just confused myself ;)
if ($user_array[0] == $_SESSION["cookiename"]){
[edited by: Birdman at 4:31 pm (utc) on Mar. 13, 2004]
if ($user_array[0] == $_SESSION["username"]){
for ($e=0; $e<count($user_array)-1; $e++){
$color[] = $user_array[$e];
}
return $color;
}
Then access your colors starting at $color[0]. If you really want to start at one, change the line to:
$color[$e+1] = $user_array[$e];