Edit report at https://bugs.php.net/bug.php?id=45972&edit=1
ID: 45972 Comment by: dillydadally at yahoo dot com Reported by: woeterman at gmail dot com Summary: Date escaping goes incorrectly Status: Not a bug Type: Bug Package: Date/time related Operating System: Linux Debian PHP Version: 5.2.6 Block user comment: N Private report: N New Comment: Ah, you're right! The distinction completely slipped my mind! I think the documentation is commenting on this here: "You can prevent a recognized character in the format string from being expanded by escaping it with a preceding backslash. If the character with a backslash is already a special sequence, you may need to also escape the backslash." I took this to mean the backslash in a tab character would have to be escaped, but on a second review, I understand what it's saying. It's a bit confusing. Perhaps an example in the documentation would help clear things up. Or maybe I'm just wrong. Anyway, if anyone hits this and wants to use double quotes, you can still do a t by typing \\t. Previous Comments: ------------------------------------------------------------------------ [2012-05-29 00:00:05] ras...@php.net dillydadally I think you missed the fact that the original report had double- quoted strings. Your version with single-quoted strings works as you would expect. eg. php > echo date('H:m:s \m \i\s\ \m\o\n\t\h'); 16:05:40 m is month ------------------------------------------------------------------------ [2012-05-28 23:57:30] dillydadally at yahoo dot com I whole-heartedly disagree that this is not a bug, as does the PHP.net documentation itself! If you look at the documentation, "\t" is used all over in the examples to represent how to type the letter t. For example, these are copied from the documentation: $today = date('\i\t \i\s \t\h\e jS \d\a\y.'); $today = date('H:m:s \m \i\s\ \m\o\n\t\h'); The backslash in the tab character should have to be escaped, so the tab character should be \\\t. What's worse is this is not expected behavior and there is no solution or note posted in the php documentation, leaving many people confused. ------------------------------------------------------------------------ [2008-09-02 11:46:23] der...@php.net That's because normal string escape rules still apply, and \t is the tab character. ------------------------------------------------------------------------ [2008-09-02 11:37:42] woeterman at gmail dot com Description: ------------ When escaping with date("\t"), it shows up as nothing instead of 't'. It seems to work fine with other characters, such as \a Reproduce code: --------------- <?php echo "1: ". date("jS \of F Y H:i:s"). "<br />"; echo "2: ". date("jS \of F Y at H:i:s"). "<br />"; echo "3: ". date("jS \of F Y \at H:i:s"). "<br />"; echo "4: ". date("jS \of F Y \a\t H:i:s"). "<br />"; echo "5: ". date("jS \of F Y \t H:i:s"). "<br />"; ?> Expected result: ---------------- 1: 2nd of September 2008 13:36:57 2: 2nd of September 2008 pm30 13:36:57 3: 2nd of September 2008 a30 13:36:57 4: 2nd of September 2008 at 13:36:57 5: 2nd of September 2008 t 13:36:57 Actual result: -------------- 1: 2nd of September 2008 13:36:57 2: 2nd of September 2008 pm30 13:36:57 3: 2nd of September 2008 a30 13:36:57 4: 2nd of September 2008 a 13:36:57 5: 2nd of September 2008 13:36:57 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=45972&edit=1