note 72847 deleted from function.strtotime by nlopess
| From: | nlopess@php.net | Date: | Sat, 03 Feb 2007 22:37:28 +0000 |
| Subject: | note 72847 deleted from function.strtotime by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122775@lists.php.net to get a copy of this message | ||
Note Submitter: allinfo at spamless dot syclone dot net
Reason: integrated
----
Example 432 doesn't escape the letter 'o' in the argument to date(), so the resulting
string doesn't look right.
<?php
$str = "September 7, 1976";
// previous to PHP 5.1.0 you would compare with -1, instead of false
if (($timestamp = strtotime($str)) === false) {
echo "The string ($str) is bogus";
} else {
/*
This doesn't work. The date() function interpolates the letter 'o' in
'of'
as an "ISO-8601 year number"
*/
echo "$str == " . date('l dS of F Y h:i:s A', $timestamp);
//September 7, 1976 == Tuesday 07th 1976f September 1976 12:00:00 AM
/*
This works. The letters o and f are escaped with slashes.
*/
echo "$str == " . date('l dS \o\f F Y h:i:s A', $timestamp);
//September 7, 1976 == Tuesday 07th of September 1976 12:00:00 AM
}
?>
According to the docs for date(), the 'o' character was added in PHP 5.1.0. It may be
worthwhile to escape every non-whitespace character in the format string, in case more functionality
is added in the future.