Re: [PHP] Please help with glob
Hi there Since glob is actually a part of the core - Are you absolutely sure that you're running PHP 4.3 2011/4/5 Al Mangkok almang...@gmail.com: Hi everyone, I am very new to PHP and trying to learn the glob() function. I copied the example on php.net : ?php foreach (glob(*.txt) as $filename) { echo $filename size . filesize($filename) . \n; } ? When I ran the script, I got this error message: Fatal error: Call to undefined function glob() in /usr/local/apache2/htdocs/hrms/globtest.php on line 2 I am running PHP 5.2.17 on CentOS 4.8 . How do I compile PHP to get the glob function in ? Please help. -- al -- 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] Please help with glob
Hi Louis, Yes, I have read that glob is only available for PHP 4.3 and I am using version 5.2.1.7 # /usr/local/bin/php -v PHP 5.2.17 (cli) (built: Feb 16 2011 15:41:35) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies # /usr/local/bin/php globtest.php Fatal error: Call to undefined function glob() in /usr/local/apache2/htdocs/hrms/globtest.php on line 2 I have read somewhere that it could be connected to glibc, not I have no idea how to fix that. Anyone ? -- al On Tue, Apr 5, 2011 at 2:25 PM, Louis Huppenbauer louis.huppenba...@gmail.com wrote: Hi there Since glob is actually a part of the core - Are you absolutely sure that you're running PHP 4.3 2011/4/5 Al Mangkok almang...@gmail.com: Hi everyone, I am very new to PHP and trying to learn the glob() function. I copied the example on php.net : ?php foreach (glob(*.txt) as $filename) { echo $filename size . filesize($filename) . \n; } ? When I ran the script, I got this error message: Fatal error: Call to undefined function glob() in /usr/local/apache2/htdocs/hrms/globtest.php on line 2 I am running PHP 5.2.17 on CentOS 4.8 . How do I compile PHP to get the glob function in ? Please help. -- al -- 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] Please help with glob
Yesterday I yum installed these: glibc-common.i386 2.3.4-2.54 glibc.i686 2.3.4-2.54 glibc-headers.i386 2.3.4-2.54 glibc-devel.i386 2.3.4-2.54 And about ten minutes ago I recompiled PHP with identical configure options as before. And this time the glob function is inside PHP. Phew. Hopefully someone else will benefit from this post. -- al On Tue, Apr 5, 2011 at 2:49 PM, Al Mangkok almang...@gmail.com wrote: Hi Louis, Yes, I have read that glob is only available for PHP 4.3 and I am using version 5.2.1.7 # /usr/local/bin/php -v PHP 5.2.17 (cli) (built: Feb 16 2011 15:41:35) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies # /usr/local/bin/php globtest.php Fatal error: Call to undefined function glob() in /usr/local/apache2/htdocs/hrms/globtest.php on line 2 I have read somewhere that it could be connected to glibc, not I have no idea how to fix that. Anyone ? -- al On Tue, Apr 5, 2011 at 2:25 PM, Louis Huppenbauer louis.huppenba...@gmail.com wrote: Hi there Since glob is actually a part of the core - Are you absolutely sure that you're running PHP 4.3 2011/4/5 Al Mangkok almang...@gmail.com: Hi everyone, I am very new to PHP and trying to learn the glob() function. I copied the example on php.net : ?php foreach (glob(*.txt) as $filename) { echo $filename size . filesize($filename) . \n; } ? When I ran the script, I got this error message: Fatal error: Call to undefined function glob() in /usr/local/apache2/htdocs/hrms/globtest.php on line 2 I am running PHP 5.2.17 on CentOS 4.8 . How do I compile PHP to get the glob function in ? Please help. -- al -- 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] DateTime using DateTimeZone Timestamp problem
On 5/04/2011, at 3:35 AM, Ian wrote: Hi, I have a problem using the php built in classes DateTime and DateTimeZone. The idea behind the following code is to return the timestamp for the current time in Singapore (or other places). What it actually returns is the timestamp for the local system. Other formatted dates appear to return correctly, which is why I am puzzled. I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS container. All packages are up to date. Am I doing something wrong or is this a bug? I can workaround this problem my parsing the correctly formatted date using strtotime() but I would like to know what's going on. This is the output of the script: Current time in Asia/Singapore is 2011-04-04 23:32:36 Timestamp for Asia/Singapore is 1301931156 Date created from previous timestamp is 2011-04-04 16:32:36 The code is : ?php $timezone=Asia/Singapore; # Create Timezone object $remote_timezone = new DateTimeZone($timezone); # Create datetime object $remote_time = new DateTime(now , $remote_timezone); # Print the date print Current time in {$timezone} ; print is {$remote_time-format(Y-m-d H:i:s)}br/; # Print the timestamp print Timestamp for {$timezone} ; print is {$remote_time-format(U)}br /; # Get the timestamp and create a date from it $timestamp = (int)$remote_time-format(U); # Show the formatted date created from timestamp print Date created from previous timestamp is ; print date(Y-m-d H:i:s,$timestamp).br/; ? May I suggest including the timezone in your date format (O or e)? It may show the two date strings to be equivalent. --- Simon Welsh Admin of http://simon.geek.nz/ Who said Microsoft never created a bug-free program? The blue screen never, ever crashes! http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DateTime using DateTimeZone Timestamp problem
On 4 April 2011 16:35, Ian php_l...@fishnet.co.uk wrote: Hi, I have a problem using the php built in classes DateTime and DateTimeZone. The idea behind the following code is to return the timestamp for the current time in Singapore (or other places). What it actually returns is the timestamp for the local system. Other formatted dates appear to return correctly, which is why I am puzzled. I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS container. All packages are up to date. Am I doing something wrong or is this a bug? I can workaround this problem my parsing the correctly formatted date using strtotime() but I would like to know what's going on. This is the output of the script: Current time in Asia/Singapore is 2011-04-04 23:32:36 Timestamp for Asia/Singapore is 1301931156 Date created from previous timestamp is 2011-04-04 16:32:36 The code is : ?php $timezone=Asia/Singapore; # Create Timezone object $remote_timezone = new DateTimeZone($timezone); # Create datetime object $remote_time = new DateTime(now , $remote_timezone); # Print the date print Current time in {$timezone} ; print is {$remote_time-format(Y-m-d H:i:s)}br/; # Print the timestamp print Timestamp for {$timezone} ; print is {$remote_time-format(U)}br /; # Get the timestamp and create a date from it $timestamp = (int)$remote_time-format(U); # Show the formatted date created from timestamp print Date created from previous timestamp is ; print date(Y-m-d H:i:s,$timestamp).br/; ? Timestamps (the integer value) do not hold the timezone data. Internally, the value represents a number of milliseconds from a point in time. So saying timestamp for Asia/Singapore isn't right. It is just Timestamp. The following script (http://pastebin.com/0MQAaYUq) may show you in a more concrete way ... ?php $a_Times = array( 'now', '2011-03-27 00:59:59', '2011-03-27 02:00:00', ); // Create Timezone objects $a_Timezones = array( 'Singapore' = new DateTimeZone('Asia/Singapore'), 'NewYork ' = new DateTimeZone('America/New_York'), 'London ' = new DateTimeZone('Europe/London'), 'UTC ' = new DateTimeZone('UTC'), ); foreach($a_Times as $s_Time) { echo 'Time : ', $s_Time, PHP_EOL; // Create datetime objects $a_DateTimes = array(); foreach($a_Timezones as $s_Timezone = $tz_Timezone) { $a_DateTimes[$s_Timezone] = new DateTime($s_Time , $tz_Timezone); } // Print the date foreach($a_DateTimes as $s_Timezone = $dt_DateTime) { echo 'Current time in ', $s_Timezone, ' : ', $dt_DateTime-format(DateTime::RSS), ' Offset : ', str_pad($dt_DateTime-getOffset(), 6, ' ', STR_PAD_LEFT), ' Timestamp : ', ($i_Timestamp = $dt_DateTime-getTimestamp()), ' Local : ', date(DateTime::RSS, $i_Timestamp), PHP_EOL; } echo PHP_EOL; } ? outputs (http://pastebin.com/mETSbR7h) ... Time : now Current time in Singapore : Tue, 05 Apr 2011 17:56:32 +0800 Offset : 28800 Timestamp : 1301997392 Local : Tue, 05 Apr 2011 10:56:32 +0100 Current time in NewYork : Tue, 05 Apr 2011 05:56:32 -0400 Offset : -14400 Timestamp : 1301997392 Local : Tue, 05 Apr 2011 10:56:32 +0100 Current time in London: Tue, 05 Apr 2011 10:56:32 +0100 Offset : 3600 Timestamp : 1301997392 Local : Tue, 05 Apr 2011 10:56:32 +0100 Current time in UTC : Tue, 05 Apr 2011 09:56:32 + Offset : 0 Timestamp : 1301997392 Local : Tue, 05 Apr 2011 10:56:32 +0100 Time : 2011-03-27 00:59:59 Current time in Singapore : Sun, 27 Mar 2011 00:59:59 +0800 Offset : 28800 Timestamp : 1301158799 Local : Sat, 26 Mar 2011 16:59:59 + Current time in NewYork : Sun, 27 Mar 2011 00:59:59 -0400 Offset : -14400 Timestamp : 1301201999 Local : Sun, 27 Mar 2011 05:59:59 +0100 Current time in London: Sun, 27 Mar 2011 00:59:59 + Offset : 0 Timestamp : 1301187599 Local : Sun, 27 Mar 2011 00:59:59 + Current time in UTC : Sun, 27 Mar 2011 00:59:59 + Offset : 0 Timestamp : 1301187599 Local : Sun, 27 Mar 2011 00:59:59 + Time : 2011-03-27 02:00:00 Current time in Singapore : Sun, 27 Mar 2011 02:00:00 +0800 Offset : 28800 Timestamp : 1301162400 Local : Sat, 26 Mar 2011 18:00:00 + Current time in NewYork : Sun, 27 Mar 2011 02:00:00 -0400 Offset : -14400 Timestamp : 1301205600 Local : Sun, 27 Mar 2011 07:00:00 +0100 Current time in London: Sun, 27 Mar 2011 02:00:00 +0100 Offset : 3600 Timestamp : 1301187600 Local : Sun, 27 Mar 2011 02:00:00 +0100 Current time in UTC : Sun, 27 Mar 2011 02:00:00 + Offset : 0 Timestamp : 1301191200 Local : Sun, 27 Mar 2011 03:00:00 +0100 Getting the the timestamp for a DateTime object
[PHP] Re: DateTime using DateTimeZone Timestamp problem
On 05/04/2011 10:11, Simon J Welsh wrote: On 5/04/2011, at 3:35 AM, Ian wrote: Hi, I have a problem using the php built in classes DateTime and DateTimeZone. The idea behind the following code is to return the timestamp for the current time in Singapore (or other places). What it actually returns is the timestamp for the local system. Other formatted dates appear to return correctly, which is why I am puzzled. I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS container. All packages are up to date. Am I doing something wrong or is this a bug? I can workaround this problem my parsing the correctly formatted date using strtotime() but I would like to know what's going on. This is the output of the script: Current time in Asia/Singapore is 2011-04-04 23:32:36 Timestamp for Asia/Singapore is 1301931156 Date created from previous timestamp is 2011-04-04 16:32:36 The code is : ?php $timezone=Asia/Singapore; # Create Timezone object $remote_timezone = new DateTimeZone($timezone); # Create datetime object $remote_time = new DateTime(now , $remote_timezone); # Print the date print Current time in {$timezone} ; print is {$remote_time-format(Y-m-d H:i:s)}br/; # Print the timestamp print Timestamp for {$timezone} ; print is {$remote_time-format(U)}br /; # Get the timestamp and create a date from it $timestamp = (int)$remote_time-format(U); # Show the formatted date created from timestamp print Date created from previous timestamp is ; print date(Y-m-d H:i:s,$timestamp).br/; ? May I suggest including the timezone in your date format (O or e)? It may show the two date strings to be equivalent. Hi, Found the problem: Unix timestamps are a moment in time and so timezones have no influences on them. They count the number of seconds since 1970-01-01 00:00 *UTC* See: http://en.wikipedia.org/wiki/Unix_time So the timestamp will always be the same no matter which timezone. I will use by workaround to get the expected timestamp for use in comparisons. Regards Ian -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] randomly random
OK gang, to spew a single line from a file of fortune cookies, I want to read it and echo one line. While I found a 4 line code which gets it done, I thought there was a preexisting command to do exactly that. Any feedback on this? -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] randomly random
On 5 April 2011 15:07, Kirk Bailey kbai...@howlermonkey.net wrote: OK gang, to spew a single line from a file of fortune cookies, I want to read it and echo one line. While I found a 4 line code which gets it done, I thought there was a preexisting command to do exactly that. Any feedback on this? motd maybe. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] randomly random
On 4/5/2011 7:07 AM, Kirk Bailey wrote: OK gang, to spew a single line from a file of fortune cookies, I want to read it and echo one line. While I found a 4 line code which gets it done, I thought there was a preexisting command to do exactly that. Any feedback on this? No, but it can be done in one line: ?php echo array_rand(@file(@$filename), 1); # if you wanted to do a couple checks, you could do the following if ( is_file(@$filename) filesize($filename) 0 ) echo array_rand(file($filename), 1); ? Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] randomly random
On Tuesday, 5 April 2011 at 16:14, Jim Lucas wrote: On 4/5/2011 7:07 AM, Kirk Bailey wrote: OK gang, to spew a single line from a file of fortune cookies, I want to read it and echo one line. While I found a 4 line code which gets it done, I thought there was a preexisting command to do exactly that. Any feedback on this? No, but it can be done in one line: ?php echo array_rand(@file(@$filename), 1); # if you wanted to do a couple checks, you could do the following if ( is_file(@$filename) filesize($filename) 0 ) echo array_rand(file($filename), 1); ? This method will eat memory unless you have a very small file. Personally I would use filesize to get the length of the file, fopen it, fseek to a random position, then track back to a newline and use fgets to get the line. Then fclose, obviously. Simples. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Ranges for case statement and a WTF moment.
On 5 April 2011 16:28, Richard Quadling rquadl...@gmail.com wrote: Hi. I just wanted to quickly see if PHP supported ranges in its switch/case statement (http://en.wikipedia.org/wiki/Ellipsis) ?php $s = intval(date('s')); switch($s) { case 0...9 : echo 'Between 0 and 9'; break; case 10...19 : echo 'Between 10 and 19'; break; case 20...29 : echo 'Between 20 and 29'; break; case 30...39 : echo 'Between 30 and 39'; break; case 40...49 : echo 'Between 40 and 49'; break; case 50...59 : echo 'Between 50 and 59'; break; default : echo 'Unknown : ', $s; } ? Completely unexpectedly, the above code runs but produces the wrong output. Interestingly, altering the number of dots and adding spaces all result in parse errors ... case 0..9 : // 2 dots, no spaces case 0 .. 9 : // 2 dots, with spaces case 0 ... 9 : // 3 dots, with spaces It was confusing that the initial code ran without a parse error, but considering that it did, it would suggest that the case values are actually meaningful in some way. php -r var_dump(10...19); Interesting output ... string(6) 100.19 And that took me a little while to work out. It's all to do with PHP's type juggling. 10...19 What I'm not sure is why the middle empty string is output as 0. 10 . . .19 becomes 10 . 0 . .19 which becomes 100.19 Oddly, more . don't work. php -r var_dump(1019); all result in parse errors. I don't know if this is a bug per se, but it is an oddity that I though I'd share. And what is even more surprising is that the initial code works in the PHP V4.0.0. So maybe an 11 years old bug. You really would have thought I'd have more to do with my time! Regards, Richard. Just tested PHP V3.0.11 and I get the same response. Seems that this is just the way it is. An oddity for since 1999-06-26 at least. Richard. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php