note 54733 added to function.date

From: Date: Wed, 13 Jul 2005 23:27:17 +0000
Subject: note 54733 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-91926@lists.php.net to get a copy of this message
To create a HTTP-date (for the use in an "Expires" header() function) use this code, according to the HTTP RFC (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1) <?php define('RFC1123_DATE',1); define('RFC850_DATE',2); define('ASCTIME_DATE',3); function http_date($format='',$timestamp=''){ /* * * Function to create a HTTP-date according to RFC 2616, section 3.3.1 * * Arguments: * $format = null | '' | RFC1123_DATE | RFC850_DATE | ASCTIME_DATE * $timestamp = null | '' | <Unix timestamp> * * Output: * String, containing a HTTP-date in the requested $format * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, check http://www.gnu.org/copyleft/gpl.html * or write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * Please don't remove this comment. * * This code was written by: * J. Hollemans * White Rhino * http://www.white-rhino.nl/ * */ if($timestamp=='') $timestamp=time(); switch($format){ case RFC1123_DATE: return date('D, d M Y H:i:s',$timestamp).' GMT'; break; case RFC850_DATE: return date('l, d-M-y H:i:s',$timestamp).' GMT'; break; case ASCTIME_DATE: return date('D M ',$timestamp).(strlen(date('j',$timestamp))==1?date(' j',$timestamp):date('j',$timestamp)).date(' H:i:s Y',$timestamp); break; default: return date('D, d M Y H:i:s',$timestamp).' GMT'; } } ?> Hope it helps you! J. Hollemans White Rhino http://www.white-rhino.nl/ ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54733 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54733&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54733&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54733&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54733&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54733&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54733&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54733&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91926) next »