I have the following HTML and PHP code to display Month, today's date and the day.
<p class="time">
<time class="icon">
<strong><?php echo date(F); ?></strong>
<em><?php echo date(l); ?></em>
<span> <?php echo date(d); ?></span>
</time>
I get errors when I use the following
ini_set('display_errors', 'On'); error_reporting(E_ALL);
Errors are:
Notice: Use of undefined constant F - assumed 'F' in C:\dir\subdir\includes\header.php on line 43 January
Notice: Use of undefined constant d ......
Notice: Use of undefined constant l ......
I checked PHP data manual at http://us2.php.net/manual/en/function.date.php
subsequently, the examples shown on php manual website led me to added the following line to the top of my file but no change.
<?php date_default_timezone_set('US/Pacific'); ?>
I'm still getting the error messages. Is there something I need to be aware of. I also tried adding the data_default_timezone_set function directly (I know it's redundant but i figured to try and see what happens). within the html tags of course to no avail
<?php date_default_timezone_set('US/Pacific'); echo date(F); ?>
<?php date_default_timezone_set('US/Pacific'); echo date(l); ?>
<?php date_default_timezone_set('US/Pacific'); echo date(d); ?>
Any thoughts? Thank you in advance!
You need to put quotes around it the string passed into the date function:
<strong><?php echo date('F'); ?></strong>
<em><?php echo date('l'); ?></em>
<span> <?php echo date('d'); ?></span>
Also, in modern PHP most developers do not use the <?php ... ?>
syntax either. Something like Smarty or Mustache is typically used.
In smarty it would look like this:
<strong>{$smarty.const.now|date_format:'%e'}</strong>
<em>{$smarty.const.now|date_format:'%A'}</em>
<span>{$smarty.const.now|date_format:'%d'}</span>
I'm not as familiar with Mustache, but it's fairly similar to Smarty but cross platform/cross language.