RE: Inconsistent php sematics witrh trim() ... or can't trim() handle assignment with same variable?

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

 



I wish I could say the same about my code, but your
remark is still fruitfull from some points of view:

1) It does work in your special case, but not with me.
2) It does not tell anything about my case.
3) It does tell - me - something about my case!

Conclusion: I need to run some few test suits
today to find out what's really going on here.

In addition I can tell that my file consist of NL as CR+LF,
or if it was the otherway around (LF+CR) - I never seams to
be able to remember the order. ;) According to 3) your NL (\n)
might encode different: either CR or LF only(?). On the other
hand trim() does acutally remove the NL when called as in the
second code example, so it can't just be the simple fact that
it does remove one, and only one, of the NL characters from
the string.

It might be an idea to investigte the input/output relation
with trim() in order to find out weather any of CR or LF (or
both) is left in the output string after trim() been applied.

The major point is thou that I do experience that trim() have
two different kind of behaviour depending on the way I call
trim(), so the question(s) is(are): what is the scope of this
behavior, and why does it happend (to me;)?

I'll try to come up with an answer on this today.


     //Anders - who never been writing php code before. ;)


-----Original Message-----
From: Frank M. Kromann
To: Svensson, B.A.T. (HKG)
Cc: 'php-windows@lists.php.net'
Sent: 2003-12-16 07:20
Subject: Re:  Inconsistent php sematics witrh trim() ... or can't
trim() handle  assignment with same variable?

I can't see a promlem with the trim() function.

Try this:

<?php

$a = " test\n";
echo "***$a***";
$a = trim($a);
echo "***$a***";
?>

output:

*** test
******test***

I have tested with both php4 and php5 from cvs.

- Frank

> Just ran into this annoying thing today:
> 
> 
> Why does this /NOT/ work to remove NL's:
> 
>     $AccNr = fgets($fp);
>     while ( !feof($fp) ) {
> 
>        $AccNr = trim($AccNr);  /// trim() DOES NOT WORK HERE
>        $InsertStr = "insert into $UpLoadTable values ('$AccNr')";
>        print "<pre>$i: Inserting: $InsertStr </pre>";
>        ob_flush();
>        mssql_query($InsertStr);
> 
>        $AccNr = fgets($fp);
>     }
> 
> while this works just fine to remove NL's:
> 
>     $AccNR = trim( fgets($fp) );  // trim WORKS JUST FINE HERE
>     while ( !feof($fp) ) {
> 
>        $InsertStr = "insert into $UpLoadTable values ('$AccNr')";
>        print "<pre>$i: Inserting: $InsertStr </pre>";
>        ob_flush();
>        mssql_query($InsertStr);
> 
>        $AccNr = trim( fgets($fp) ); // trim WORKS JUST FINE HERE
> 
>     }
> 
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux