ID: 12161
Updated by: sniper
Old Status: Feedback
Status: Closed
Bug Type: Date/time related
Operating System: Windows 98
PHP Version: 4.0.6
New Comment:

Should be closed..

Previous Comments:

[2001-07-16 06:01:00] [EMAIL PROTECTED]

This is not a PHP bug, it is a bug in your code, related to
the use of preg_replace.
Example: printdate("ddd");

You're expecting:

You should be getting:

Mon is becoming date("M")on, or something like it.
I don't know if this is what preg_replace SHOULD be
doing or seems to be making multiple passes
until it can no longer replace anything. Could someone
who knows about preg_replace please verify whether this
is the correct behavior or not?

In the meantime, I fixed the userland code so that it performs
as you expected. You can find it at


[2001-07-14 04:24:44] [EMAIL PROTECTED]

PHP Authors,

My names are James Hitz, author of a website that provides 
free PHP tutorials.

I was creating a tutorial on user-defined functions and was working on one that 
accepts a string containing a date format (eg. dd-mmm-yy) and outputs  the date in the 
specified format.  The code is as follows:


  function printdate($subject){

        $search = array( 


                 "/[y]{1,2}/i" );

        $replace = array(


                date("y") );

        $newdate =   preg_replace($search,$replace, $subject);
        //return the formatted date
        return $newdate;


On my Win 98 (Second Edition) system running php version 4.06, I evoked the following 
above functrion using  the following code snippet:

    print printdate("dddd ddd, dd d m mm mmm mmmm y yy yyy yyyy");

This produced the following output:

    Thurs12a01 Thu, 12 12 7 07 Jul Jul01 01 01 2001 2001

Aparrently, I expected this to have produced something like this:

    Thursday Thu, 12 12 7 07 Jul July 01 01 2001 2001

The parsing of the date() function seems not to act 'normal'.  The documentation I 
have states as follows in regard to the date() function: 

    (PHP 3, PHP 4 )

    date -- Format a local time/date

    string date (string format [, int timestamp])

    Returns a string formatted according to the given  
    format string using the given timestamp or the current 
    local time if no timestamp is given. 

    The following characters are recognized in the format

    d - day of the month, 2 digits with leading zeros; i.e.
     "01" to "31" 

    D - day of the week, textual, 3 letters; i.e. "Fri" 

    F - month, textual, long; i.e. "January" 

    j - day of the month without leading zeros; i.e. "1"
        to "31" 

    l (lowercase 'L') - day of the week, textual, long;
       i.e. "Friday" 

    m - month; i.e. "01" to "12" 

    M - month, textual, 3 letters; i.e. "Jan" 

    n - month without leading zeros; i.e. "1" to "12" 

    r - RFC 822 formatted date; i.e. "Thu, 21 Dec 2000 16:01:07 +0200" 

    Y - year, 4 digits; i.e. "1999" 

    y - year, 2 digits; i.e. "99" 

    z - day of the year; i.e. "0" to "365" 


Is this a bug in the code or a bug in the documentation?  Seems to me like one of 
those. Please advise. I am making a tutorial that will make use of the above function 
and would appreciate if you would tell me what to tell my audience.

The tutorials I am make are very good for all - even complete beginners, so you can 
bundle them in your PHP distributions, or you can point users to  All tutorials are free.

Thanking you.
James N. Hitz


Edit this bug report at

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to