Re: Re: Not getting expected result from file()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



trim is probably sub-optimal, as you MIGHT have leading/trailing
whitespace as part of the actual data at some point.

You should trim off ONLY one last newline character, no more, no less.

I dunno why it's not working still though...

On Mon, June 11, 2007 12:14 am, kvigor wrote:
> OK, I trimmed the elements in the array. using var_dump() it shows
> strings
> are identical, however nothing is storing in DB still.
>
> view new code
> =====================================//doesn't store in central still,
> also
> shows no MySQL errors.
> $theFileArray = file('C:\htdocs\folder1\file.txt');
>
> function trim_value(&$value)
> {
>     $value = trim($value);
> }
>
> array_walk($theFileArray, 'trim_value');
>
>
> if(isset($_POST['strName'], $_POST['strCity'], $_POST['strState']))
> {
>  $space = " ";
>  $stringOne = $_POST['strName']. $space. $_POST['strCity']. $space .
> $_POST['strState'];
>
> }
>  if(in_array($storeInfo, $theFileArray))
>  {
>   $queryCentral = "INSERT INTO central (conName, conAddress, conCity,
> conState, conZip, conPhone, schName, schAddress, schCity, schState,
> schZip,
> strName, strCity, strState) VALUES('$regName', '$regAddress',
> '$regCity',
> '$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress',
> '$sclCity',
> '$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState')";
>
>   mysql_query($queryCentral, $connection) or die("Query failed: ".
> mysql_error($connection));
>  }
>
>
> else
> {
> $queryUnknown = "INSERT INTO unknown (conName, conAddress, conCity,
> conState, conZip, conPhone, schName, schAddress, schCity, schState,
> schZip,
> strName, strCity, strState) VALUES('$regName', '$regAddress',
> '$regCity',
> '$regState', '$regZip', '$regPhone', '$sclName', '$sclAddress',
> '$sclCity',
> '$sclState', '$sclZip', '$stoName', '$stoCity', '$stoState')";
> mysql_query($queryUnknown, $connection) or die("Query failed: ".
> mysql_error($connection));
> }
> =====================================
>
> "David Robley" <robleyd@xxxxxxxxxxxxxx> wrote in message
> news:57.D0.40822.538CC664@xxxxxxxxxxxxxxx
>> 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.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux