Jump to content

Archived

This topic is now archived and is closed to further replies.

adam_gardner

compare values in a file

Recommended Posts

hi guys,

what i want to do is use an if - else to compare a variable to a load of variables. I could of course use an OR, but i've got about 200 variable to compare -- long loop!

what i want to do is compare it to a files content - so for example i have a file called [b]compare.txt[/b]

my compare.txt file has the lines -

a
b
c
d
e
(etc.)

so (pseudocode) -

$myvariable='f'
if $myvariable == compare.txt variables
[i]do something[/i]
else
[i]do something else[i]

so in this case it would return false


is there a way to do this or would i have to list a,b,c & d as seperate variables?

thanks for the help!

Adam

Share this post


Link to post
Share on other sites
Try this:
[code]<?php
$compare = file('compare.txt')
$var = 'f';
if (in_array($var."\n",$compare)) echo 'Variable ' . $var. ' found';
?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.