Re: [PHP] Re: newbie question about storing big5 codes into mysql-5.0.24a

2007-03-25 Thread Stut
Man-wai Chang wrote:
 create table temp ( big5 char(2) ) character set big5 collate big5_bin;
 insert into temp ( big5 ) values ( 0x9f54 );
 insert into temp ( big5 ) values ( 0x9f53 );
 The 2nd query will report duplicated key. How should I fix the problem?
 What does this has to do with PHP?
 First of all I don't see any PHP code, and second this is an error in
 your SQL query, so you should be on the MySQL list.
 
 I used mysqli_query() to send the SQL. How could I make it work?

That really doesn't make this question PHP-related. You really do need
to ask on a MySQL mailing list. This has nothing to do with PHP, and
you're more likely to get a useful answer from a MySQL-specific list.

If you really want to try and justify asking this question here, try the
queries in the command-line MySQL client. If it works there but not
through mysqli_query() then you might have a case for asking here.

-Stut

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



Re: [PHP] Re: newbie question about storing big5 codes into mysql-5.0.24a

2007-03-25 Thread Jochem Maas
Man-wai Chang wrote:
 queries in the command-line MySQL client. If it works there but not
 through mysqli_query() then you might have a case for asking here.
 
 For the 13081 chinese alphabets I tried, only 1 one failed, and it's
 0x9f54. mysqli_query() should have escaped the string for me.

mysqli_query() doesn't escape anything for you - your assumption that
it *should* is WRONG.

try this: http://php.net/manual/en/function.mysqli-real-escape-string.php

 So ...
 
 I suppose most PHP programmers are also experts in MySQL (they are
 basically tied). 

incorrect supposition. most php programmers have experience using
RDBMs because of the dynamic nature of the websystems they build.

mysql and php and not tied at all .. they just happen to be used together
frequently.

 SO I tried my luck here. :)
 

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-11 Thread Jon Anderson

Satyam wrote:

for ($x=0;$x1000;$x++) {
   echo ' trtdX is ' , $x , '/td/tr';
}
This seems to be a hair faster. I extended the test to 1 requests 
(still concurrency 10) to make the test a little more reproducible:


echo str,var,str did 604.65 requests a second where trtd?= $x 
?/td/tr did 599.63 requests a second. I also tried echo str . var . 
str, and it came in at about 584.55 requests a second.  printf(str %i 
str,var) came out at 547.01 requests a second and printf(str %s 
str,var) was only 452.03 requests a second.
Can you try and time that one so we have comparable results?  This one 
should be second best:


for ($x=0;$x1000;$x++) {
   echo trtdX is $x/td/tr;
}

Approximately 330 (?!) requests a second for that one.
Back again to what would be 'longer', well, in your example, the whole 
header, up to the loop itself should be faster if sent out of PHP. 
Likewise, you could echo $buffer right after the loop, drop out of PHP 
and send the footer as plain HTML.  This, of course, is harder to time 
since it happens only once.  I admit though that I did time the 
options I listed and on the 'dropping in and out of PHP' I'm relying 
on the PHP manual ( see 
http://www.php.net/manual/en/language.basic-syntax.php, the first 
paragraph after the examples) and the source of the lexical scanner, 
which supports that, though your numbers do contradict it.  Interesting. 
I'm not sure that my results would count as contradictory - I'm running 
APC which would likely throw performance related numbers out of whack as 
compared to out-of-the-box PHP.


Because of that, I wouldn't recommend anyone take my numbers too 
seriously - they're just an example taken from my server: 1.8 GHz 
SMP/1G/RAID5/Linux 2.6.17.7/Apache 2.2.3/PHP 5.1.6/APC 3.0.12p2. Anyone 
else's results would probably vary widely.


jon

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-11 Thread Stut

How bored am I?

This bored: http://dev.stut.net/phpspeed/

Server is running PHP 5.1.2 (really should upgrade that) with no caches 
of any sort.


-Stut

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-11 Thread tedd

At 4:56 PM +0100 9/11/06, Stut wrote:

How bored am I?

This bored: http://dev.stut.net/phpspeed/

Server is running PHP 5.1.2 (really should upgrade that) with no 
caches of any sort.


-Stut


Which begs the question, does it make much of a difference? (not you 
being bored, but the rather speed concers).


With all the things out there that can slow your browsers reaction 
time in presenting some result, does a couple of seconds count much 
in the over all scheme of things?


I know, purest will say that they want to make whatever they do as 
fast as possible, but is that time to make it faster be better spent 
elsewhere? We used to have to worry about the size of our strings, 
but now we can place the kjv of the bible in one. So, what's the 
point of counting characters in strings now?


I suspect at some point, probably soon, speed isn't going to matter much.

Opinions?

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-11 Thread Satyam
I admit I'm totally surprised about the buffered results.  Nevertheless, may 
I sugest you add the following to the series of tests?:


   h3Using line-by-line single-quoted echobr/with comma separated 
arguments/h3

?php
   $start = mt();
   print 'table style=display:none; id=table2a';
   for ($x = 0; $x  $iterations; $x++)
   {
   echo 'trtdX is/tdtd',$x,'/td/tr';
   }
   print '/table';

   $duration = mt() - $start;
   print 'pTook '.number_format($duration, 4).' seconds/p';
?
   praquo; a id=table2alink
   href=# 
onclick=document.getElementById('table2a').style.display='block';
   document.getElementById('table2alink').style.display='none';return 
false;

   Reveal output/a/p

There seems to be one thing rarely anybody remembers, echo admits multiple 
arguments, and as the numbers will show, (or at least they do in my 
machine), they are the second best option.


Satyam


- Original Message - 
From: Stut [EMAIL PROTECTED]

To: Jon Anderson [EMAIL PROTECTED]
Cc: Satyam [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Monday, September 11, 2006 5:56 PM
Subject: Re: [PHP] Re: Newbie question about ?= ?



How bored am I?

This bored: http://dev.stut.net/phpspeed/

Server is running PHP 5.1.2 (really should upgrade that) with no caches of 
any sort.


-Stut

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




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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-11 Thread Stut

Satyam wrote:
I admit I'm totally surprised about the buffered results.  
Nevertheless, may I sugest you add the following to the series of tests?:


   h3Using line-by-line single-quoted echobr/with comma 
separated arguments/h3

snip

There seems to be one thing rarely anybody remembers, echo admits 
multiple arguments, and as the numbers will show, (or at least they do 
in my machine), they are the second best option.


Done, but again it doesn't seem to make any significant difference to 
the performance.


-Stut

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-11 Thread Stut

tedd wrote:

At 4:56 PM +0100 9/11/06, Stut wrote:

How bored am I?

This bored: http://dev.stut.net/phpspeed/

Server is running PHP 5.1.2 (really should upgrade that) with no 
caches of any sort.


-Stut


Which begs the question, does it make much of a difference? (not you 
being bored, but the rather speed concers).


With all the things out there that can slow your browsers reaction 
time in presenting some result, does a couple of seconds count much in 
the over all scheme of things?


I know, purest will say that they want to make whatever they do as 
fast as possible, but is that time to make it faster be better spent 
elsewhere? We used to have to worry about the size of our strings, but 
now we can place the kjv of the bible in one. So, what's the point of 
counting characters in strings now?


I suspect at some point, probably soon, speed isn't going to matter much.

Opinions?


I would have to agree. Having watched the server CPU load while playing 
with this test script it would  appear that the performance can be 
skewed a lot more by that than by the method you use for squidging out 
the output.


As a curiosity I've also added a test using ?php print $x; ? and 
bizarrely that appears to be slightly faster than ?=$x?.


Weird.

-Stut

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-11 Thread Stut

Jon Anderson wrote:

Stut wrote:

How bored am I?

This bored: http://dev.stut.net/phpspeed/

Server is running PHP 5.1.2 (really should upgrade that) with no 
caches of any sort. 
Just looking through the source, could you try changing the first 
example to put the output all on one line? It's the only one that does 
the row output on multiple indented lines - I'm kind of curious what 
effect (if any) that has on the results.


Done. Doesn't seem to make a difference - I didn't expect it to.

I also tried this on my own server. With the opcode cache, the results 
seem to be the inverse of yours without.


I would have been surprised if an opcode cache had made a huge 
difference. I don't think the Zend Engine is intelligent enough to 
compile the various different tests to the same set of opcodes - but I 
could be wrong. I'm still quite new to the PHP internals.


Also, with either server, the first three results seem to vary wildly, 
but the last two always seem to come out the same. I'm not sure why 
that is...


As I said in another post, the performance varies wildly with the load 
on the server.


-Stut

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-11 Thread Satyam
- Original Message - 
From: Stut [EMAIL PROTECTED]

To: Satyam [EMAIL PROTECTED]
Cc: php-general@lists.php.net
Sent: Monday, September 11, 2006 6:32 PM
Subject: Re: [PHP] Re: Newbie question about ?= ?



Satyam wrote:

I admit I'm totally surprised about the buffered results.  Nevertheless,
may I sugest you add the following to the series of tests?:

   h3Using line-by-line single-quoted echobr/with comma separated
arguments/h3
snip

There seems to be one thing rarely anybody remembers, echo admits
multiple arguments, and as the numbers will show, (or at least they do in
my machine), they are the second best option.


Done, but again it doesn't seem to make any significant difference to the
performance.

-Stut




When I run those tests locally, the numbers are totally different and the
performance of one over the other comes out far clearer.  I can only assume
that the numbers in the test run  in a remote server are so much influenced
by the ability of the server to push out the characters into the output
stream that the processing time itself is of very little relevance.  This
table shows the numbers for the different tests as run on my machine,
locally (where output streaming is irrelevant) and run from your site:

Using ?=$x?Took 0.2801 secondsTook
3.5937 seconds

Using ?php print $x; ?Took 0.3286 secondsTook 5.2654 seconds

Using line-by-line single-quoted print:Took 0.1215 secondsTook
3.2256 seconds

Using line-by-line single-quoted echo
with comma separated argumentsTook 0.2542 secondsTook 3.2220
seconds

Using line-by-line double-quoted print Took 0.1782 secondsTook
3.3129 seconds

Using buffered single-quoted printTook 0.0277 secondsTook 3.3077
seconds

Using buffered double-quoted printTook 0.2038 seconds Took 3.3012
seconds

It would seem that it takes about 3 seconds to push those bytes into the
network, the actual processing times get completely masked behind a simple
glitch in the throughput of the communication line.  While the differences
on the rightmost column (except for the second one, which is way off) are no
more than 5%, in the middle column the differences are up to 10 to 1.  But
then there is that second row, which is so much higher and it is so in both
columns.

Unfortunately, I cannot make much sense about all this.  I don't get it.
Nevertheless, something it is clear is that buffering all the output first
and then pushing it out all at once seems to beat them all, specially using
single quoted strings.  Run locally, the differences are amazing!

Satyam

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-11 Thread tedd

At 5:36 PM +0100 9/11/06, Stut wrote:

tedd wrote:

Opinions?


I would have to agree. Having watched the server CPU load while 
playing with this test script it would  appear that the performance 
can be skewed a lot more by that than by the method you use for 
squidging out the output.


As a curiosity I've also added a test using ?php print $x; ? and 
bizarrely that appears to be slightly faster than ?=$x?.


Weird.


My guess would be that it's in the interpreter -- the look-up for 
? as compared to ?php may be delayed because of checking for 
the short-tag option-on, or something similar. But, I admittedly 
don't know.


However, I strongly suspect that drawing to the screen will take 
longer than executing any = or print statement anyway. So 
regardless of the time saved in computation, the delivery would 
appear identical. It reminds me of the hurry-up and wait saying we 
had in the Army some 50 years back.


tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-10 Thread Satyam


- Original Message - 
From: Al [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Sunday, September 10, 2006 5:52 PM
Subject: [PHP] Re: Newbie question about ?= ?



Mike Borrelli wrote:

Good day,

While I've been using php for more than a little while now, I've never
understood why the use of the ?= ...? short tag is noted to be
avoided.

Or rather, I understand that there's an option to disable it, and that's
why it's noted in this way, but I don't understand why it's disabled? 
What's gained by writing ?php echo some_function(); ? over ?=

some_function(); ?

Thanks in advance.

Cheers,
Mike
Structurally, there is a far better way to compile your html pages.  This 
approach is easier to design and debug and it is faster since it sends one 
complete packet instead of one for every short tag. And, it saves using 
ob_start() and ob_flush().


Consider:

$report= '';

$report .= function() [or whatever]

. repeat as necessary to assemble your complete page.

Then simply

echo $report;



Actually, in my experience, that is not the case, my e-mail from more than a 
year ago must be somewhere there in the archives, but what you sugest is not 
the fastest.


The fastest is to escape out of php (with a ? ) for the longer invariable 
parts of immutable HTML. Stepping out from PHP and in again is handled by 
the lexical scanner, it doesn't even reach the parser level so, for all 
effects, the PHP interpreter is basically frozen at the point before the ? 
was found. For the sake of completeness, the ? is translated as a ; for the 
parser so it ends any statement that could have been left open, but it does 
not bother the parser at all for all the rest of the characters found until 
a ?php tag (or equivalent) is found.  If the lexer didn't issue a ; for a 
?, the following code would be valid:


echo 'This ' , ? is ?php 'not valid';

For the variable parts, the best is to issue as little echos as possible 
with its arguments separated by commas, not with dots.  Most people don't 
realize that echo taks a list of arguments, a list separated by commas. 
Thus, in the ratings, from best to worst, it goes:


echo 'p' , $something, '/p';
echo p$something/p
echo 'p' . $something . '/p';
echo 'p'; echo $something; echo '/p';

The reason for this is that generating a single string either from variable 
interpolation as in the second case or by concatenating the arguments, as in 
the third,  requires a lot of memory handling for the strings and its 
intermediate and final results.  Some of it might be delayed until the page 
is served so the time the garbage collector takes to clean it up might not 
be fully reflected in the processing time of a single page, but it does 
affect the overall throughput of the server.  Notice also that I have used 
single quotes whenever possible, which is slightly faster since the parser 
has much less to look for within it.


Finally, the first option is the fastest just as a C++ iostream or a Java 
StringBuffer are faster than plain strings: since you know you will only 
append to the end of them, the characters echoed go into a much more 
efficient character buffer instead of a more complex string which has to be 
available for all sorts of string operations.


Satyam

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-10 Thread Jon Anderson

Al wrote:
Structurally, there is a far better way to compile your html pages.  
This approach is easier to design and debug and it is faster since it 
sends one complete packet instead of one for every short tag. And, it 
saves using ob_start() and ob_flush().


Consider:

$report= '';

$report .= function() [or whatever]

. repeat as necessary to assemble your complete page.

Then simply

echo $report;
I thought I'd look into this, because I'm a bit of a performance nut - I 
like  my code to run as fast as possible at all times. I wrote up a 
quick buffer v.s. direct benchmark for this, and the winner is clear: 
direct output is much faster. (If my example below isn't  what you 
meant, please let me know. I'm always happy to hear  new ways  to 
improve my code.)


Best of 3 runs with apache bench (concurrency 10, 1000 requests total):
Direct output: 582 requests a second
Buffer var: 286 requests a second

I believe the margin would get wider with real-world usage, as the 
buffer variable would increase in size. My test code is copied below.


jon

--- Direct output: testecho.php ---

html
head
style type=text/wastespacetosimulateastylesheet
style1 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style2 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style3 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style4 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
/style
/head
bodytable

?php for ($x=0;$x1000;$x++) { ?
   trtdX is ?= $x ?/td/tr
?php } ?

/table/body
/html

--- Buffered output: testbuffer.php ---

?php

$buffer = '
html
head
style type=text/wastespacetosimulateastylesheet
style1 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style2 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style3 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style4 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
/style
/head
bodytable';

for ($x=0;$x1000;$x++) {
   $buffer .= trtdX is $x/td/tr;
}

$buffer .= '/table/body
/html';

echo $buffer;
?

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



Re: [PHP] Re: Newbie question about ?= ?

2006-09-10 Thread Satyam


- Original Message - 
From: Jon Anderson [EMAIL PROTECTED]

To: php-general@lists.php.net
Cc: Al [EMAIL PROTECTED]
Sent: Sunday, September 10, 2006 9:16 PM
Subject: Re: [PHP] Re: Newbie question about ?= ?



Al wrote:
Structurally, there is a far better way to compile your html pages.  This 
approach is easier to design and debug and it is faster since it sends 
one complete packet instead of one for every short tag. And, it saves 
using ob_start() and ob_flush().


Consider:

$report= '';

$report .= function() [or whatever]

. repeat as necessary to assemble your complete page.

Then simply

echo $report;
I thought I'd look into this, because I'm a bit of a performance nut - I 
like  my code to run as fast as possible at all times. I wrote up a quick 
buffer v.s. direct benchmark for this, and the winner is clear: direct 
output is much faster. (If my example below isn't  what you meant, please 
let me know. I'm always happy to hear  new ways  to improve my code.)


Best of 3 runs with apache bench (concurrency 10, 1000 requests total):
Direct output: 582 requests a second
Buffer var: 286 requests a second

I believe the margin would get wider with real-world usage, as the buffer 
variable would increase in size. My test code is copied below.


jon

--- Direct output: testecho.php ---

html
head
style type=text/wastespacetosimulateastylesheet
style1 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style2 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style3 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style4 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
/style
/head
bodytable

?php for ($x=0;$x1000;$x++) { ?
   trtdX is ?= $x ?/td/tr
?php } ?

/table/body
/html

--- Buffered output: testbuffer.php ---

?php

$buffer = '
html
head
style type=text/wastespacetosimulateastylesheet
style1 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style2 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style3 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
style4 {
   a = 1;
   b = 2;
   c = 3;
   d = 4;
   e = 5;
   f = 6;
}
/style
/head
bodytable';

for ($x=0;$x1000;$x++) {
   $buffer .= trtdX is $x/td/tr;
}

$buffer .= '/table/body
/html';

echo $buffer;
?

--
In my message I was careful to mention that stepping in and out of PHP was 
good 'for the longer invariable  parts of immutable HTML'.  What could be 
considered 'longer' is certainly a matter discussion, your results prove 
that this is not long enough.  Notice that when the parser finds the '?=', 
it converts it into the equivalent of ? echo, thus, though the echo is 
not explicitly there, from the parser on is as if it were.   Then, since you 
have an echo, why not use it for all of the output?The equivalent to 
what I showed as the second best, which would be the first best with 
'shorter' strings would be the following:


for ($x=0;$x1000;$x++) {
   echo ' trtdX is ' , $x , '/td/tr';
}

Can you try and time that one so we have comparable results?  This one 
should be second best:


for ($x=0;$x1000;$x++) {
   echo trtdX is $x/td/tr;
}

Back again to what would be 'longer', well, in your example, the whole 
header, up to the loop itself should be faster if sent out of PHP. 
Likewise, you could echo $buffer right after the loop, drop out of PHP and 
send the footer as plain HTML.  This, of course, is harder to time since it 
happens only once.  I admit though that I did time the options I listed and 
on the 'dropping in and out of PHP' I'm relying on the PHP manual ( see 
http://www.php.net/manual/en/language.basic-syntax.php, the first paragraph 
after the examples) and the source of the lexical scanner, which supports 
that, though your numbers do contradict it.  Interesting.


Satyam

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



RE: [PHP] Re: Newbie: Question about filesize()

2002-02-06 Thread Martin Towell

that should be okay - it's to make sure that it is exactly equal to (as
opposed to equates to be equal to)

eg (0 === false)  = false
   (0 ==  false)  = true

-Original Message-
From: Ben Crawford [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 07, 2002 2:28 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Newbie: Question about filesize()


You also seem to have an extra equals. Your loop should read:

while (false != ($file=readdir($handle))){

It should come up as an error, but I'm not sure.

Ben

Manuel Ritsch wrote:

 Hello There

 I'm new to PHP and trying to code a function that reads all teh files out
of
 a directory and printing out a link and the filesize,
 but it seems that the filesize() function doesn't work, here's the code so
 far:

  $handle = opendir ('images');
  echo Files:brbr;
  while (false !== ($file = readdir ($handle))) {
  if($file != .  $file != ..)
  {
  $file_s = filesize($file);
  echo a href=images/$file$file/a
Filesize:
 $file_sbr;
  }
  }
  closedir($handle);

 and the output is somethingl ike this:

 Files:
 button_test_04.gif Filesize:
 button_test_03-down.gif Filesize:
 lilextras_01.gif Filesize:
 (and so on)...

 You see, there's no Filesize and I don't know why, please help me

 -- manu


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



Re: [PHP] Re: Newbie: Question about filesize()

2002-02-06 Thread Jeff Sheltren

At 10:27 AM 2/6/2002 -0500, Ben Crawford wrote:
You also seem to have an extra equals. Your loop should read:

while (false != ($file=readdir($handle))){

I think you could eliminate the false != in the while condition...

It should be just the same if you write
while (($file = readdir($handle)))

right?

-Jeff




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




Re: [PHP] Re: Newbie: Question about filesize()

2002-02-06 Thread Lars Torben Wilson

On Wed, 2002-02-06 at 07:27, Ben Crawford wrote:
 You also seem to have an extra equals. Your loop should read:
 
 while (false != ($file=readdir($handle))){
 
 It should come up as an error, but I'm not sure.
 
 Ben

No, that's the 'identical' operator, which returns true when its
operands are both equalivalent and of the same type:

  http://www.php.net/manual/en/language.operators.comparison.php


Cheers,

Torben

-- 
 Torben Wilson [EMAIL PROTECTED]
 http://www.thebuttlesschaps.com
 http://www.hybrid17.com
 http://www.inflatableeye.com
 +1.604.709.0506


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




Re: [PHP] Re: Newbie: Question about filesize()

2002-02-06 Thread Lars Torben Wilson

On Wed, 2002-02-06 at 15:33, Jeff Sheltren wrote:
 At 10:27 AM 2/6/2002 -0500, Ben Crawford wrote:
 You also seem to have an extra equals. Your loop should read:
 
 while (false != ($file=readdir($handle))){
 
 I think you could eliminate the false != in the while condition...
 
 It should be just the same if you write
 while (($file = readdir($handle)))
 
 right?
 
 -Jeff

Wrong, actually. If you have any files in that directory which have
names which would evaluate as false in PHP, then your way will fail on
them and you'll get a truncated directory listing. Do 'touch 0' in a 
directory and give it a shot; you'll see what I mean.

However, the original example does the same thing, since it only checks
whether the result of the readdir() evaluates to FALSE, not whether it
actually is a boolean FALSE value. The correct way to do this is:

  while (FALSE !== ($file = readdir($handle))) {
 . . . 
  }

Note the !== instead of !=.


Hope this helps,

Torben

-- 
 Torben Wilson [EMAIL PROTECTED]
 http://www.thebuttlesschaps.com
 http://www.hybrid17.com
 http://www.inflatableeye.com
 +1.604.709.0506


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