Re: Not getting expected result from file()

From: Date: Tue, 12 Jun 2007 04:00:51 +0000
Subject: Re: Not getting expected result from file()
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-256668@lists.php.net to get a copy of this message
Found out the issue this afternoon. I realized that my .txt file was tab delimited and not space delimited. So I changed $space to equal $tab and query was successful! All is working now. Thanks to all who replied. I appreciate all. "David Robley" <robleyd@ozemail.com.au> wrote in message news:57.D0.40822.538CC664@pb1.pair.com... > kvigor wrote: > >> Hello, >> >> I'm using the file function create an array. I'm using a value from a >> form to see if it matches in elements in the array. >> >> My problem is I expect the condition to be true but info but my DB isn't >> populated as I in the right DB... >> =================Code >> Begins====================================================== >> $theFileArray = file('C:\htdocs\folder1\file.txt'); >> > > Your problem starts here - file returns the file in an array. Each element > of the array corresponds to a line in the file, with the newline still > attached. When you compare to a string without the newline at the end, the > comparison fails. > > If you have php > 5.0.0 you can use the FILE_IGNORE_NEW_LINES flag in the > file() arguments, otherwise use trim() to remove trailing whitespace from > the array elements. > > > > Cheers > -- > David Robley > > "I hate playing craps," Tom said dicily. > Today is Boomtime, the 16th day of Confusion in the YOLD 3173.

« previous php.general (#256668) next »