Jump to content


Photo

compare values in a file


  • Please log in to reply
1 reply to this topic

#1 adam_gardner

adam_gardner
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 11 April 2006 - 02:59 PM

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 compare.txt

my compare.txt file has the lines -

a
b
c
d
e
(etc.)

so (pseudocode) -

$myvariable='f'
if $myvariable == compare.txt variables
do something
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

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 11 April 2006 - 03:42 PM

Try this:
<?php
$compare = file('compare.txt')
$var = 'f';
if (in_array($var."\n",$compare)) echo 'Variable ' . $var. ' found';
?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users