note 54733 deleted from function.date by nlopess

From: Date: Sat, 30 Jul 2005 16:49:53 +0000
Subject: note 54733 deleted from function.date by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-92769@lists.php.net to get a copy of this message
Note Submitter: J.Hollemans (at} white-rhino {dot) nl ---- 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/

« previous php.notes (#92769) next »