Using Text Within date()
Imagine you want to output the current date (or a specific date) and use custom strings in it. The code could look like a mess if you are trying it like this: <?php echo 'Today is the ' . date('jS') . ' day of the month ' . date('F'); ?> Using Ordinary Characters in date() (date.php) <?php echo date('\To\d\a\y \i\s \t\he jS \d\a\y of F'); ?> The output of this script is something like this, depending on the current date: Today is the 3rd day of the month May The behavior of date() is the following: All characters within the first parameter that bear a special meaning (for example, formatting symbols) get replaced by the appropriate values. All other characters, however, remain unchanged. If a character is escaped using the backslash character (\), it is returned verbatim. So, the code at theF beginning of this phrase shows a new version of the code that only uses one call to date().
|