Re: [PHP] Please help with glob

2011-04-05 Thread Al Mangkok
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  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
>  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 :
>>> Hi everyone,
>>> I am very new to PHP and trying to learn the glob() function. I copied
>>> the example on php.net :
>>>
>>> >> 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



[PHP] Re: DateTime using DateTimeZone Timestamp problem

2011-04-05 Thread Ian
On 04/04/2011 18:02, Ashley Sheridan wrote:


> 
> What do you mean it only returns the timestamp for the local system? Did
> you want PHP to know what time the visitors are on? PHP won't know about
> that, all you can do is set the timezone for the script based on some
> information you're receiving from a clients machine, otherwise PHP won't
> know, because it's only run on the server and doesn't know about the
> client machines? Is this what you're trying to do, or did I
> misunderstand?
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk

Hi,

I want the code to return the timestamp for the current time in
Singapore.  The format command returns different result if the 'U' for
timestamp is specified.  It also returns the same (wrong) result for
DateTime::getTimestamp() as well.

The clients are booking entry into a place at a specific time, for
example 7am in Singapore on the 12 April. Clients can book right up to
the entry time (if there is space available).  I want to make sure they
are not trying to book in the past.

The booking system is in the UK but clients can book from anywhere.  I
cannot rely on them having the right time on their systems (or being in
the right place). Plus this would mean relying on client supplied data,
which is a no-no ;)

I have previously used a gmt offset, which was good enough as there are
not that many people who book close to the entry time.  But now its time
to improve this and use proper time zone info which can change without
my input.


If no-one can find a problem with my code I will submit it as a bug.

Thanks

Ian
-- 





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



Re: [PHP] DateTime using DateTimeZone Timestamp problem

2011-04-05 Thread Simon J Welsh
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 :
> 
>  
> $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")}";
> 
> # Print the timestamp
> print "Timestamp for {$timezone} ";
> print "is {$remote_time->format("U")}";
> 
> # 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)."";
> 
> ?>

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

2011-04-05 Thread Richard Quadling
On 4 April 2011 16:35, 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 :
>
> 
> $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")}";
>
> # Print the timestamp
> print "Timestamp for {$timezone} ";
> print "is {$remote_time->format("U")}";
>
> # 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)."";
>
> ?>

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 ...

 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 will return the
timestamp appropriately converted to the local timezone.

If you don't want to lose the timezone, then 

[PHP] Re: DateTime using DateTimeZone Timestamp problem

2011-04-05 Thread Ian
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 :
>>
>> >
>> $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")}";
>>
>> # Print the timestamp
>> print "Timestamp for {$timezone} ";
>> print "is {$remote_time->format("U")}";
>>
>> # 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)."";
>>
>> ?>
> 
> 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

2011-04-05 Thread Kirk Bailey
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

2011-04-05 Thread Richard Quadling
On 5 April 2011 15:07, 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?

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

2011-04-05 Thread Jim Lucas
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:

 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

2011-04-05 Thread Stuart Dallas
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:
> 
>  
> 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] Ranges for case statement and a WTF moment.

2011-04-05 Thread Richard Quadling
Hi.

I just wanted to quickly see if PHP supported ranges in its
switch/case statement (http://en.wikipedia.org/wiki/Ellipsis)



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.



-- 
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



[PHP] Re: Ranges for case statement and a WTF moment.

2011-04-05 Thread Richard Quadling
On 5 April 2011 16:28, Richard Quadling  wrote:
> Hi.
>
> I just wanted to quickly see if PHP supported ranges in its
> switch/case statement (http://en.wikipedia.org/wiki/Ellipsis)
>
>  $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