What I'm trying to do is display the local date using PHP. Right now I have a javascript solution that prints the month that corresponds with the php variable for the month in whatever language I want. For example for <?php echo $one; ?>
(January) it can be populated with January (english), Enero (spanish), or Gennaio (italian).
Is there any way to convert this bit of code completely to PHP? if not, is there any way I can turn the code into a php variable so I can just put something like <?php echo $date; ?>
and still define $one
, $two
, $three
, etc?
<script type="text/javascript">
var month = new Array();
month[0] = "<?php echo $one; ?>";
month[1] = "<?php echo $two; ?>";
month[2] = "<?php echo $three; ?>";
month[3] = "<?php echo $four; ?>";
month[4] = "<?php echo $five; ?>";
month[5] = "<?php echo $six; ?>";
month[6] = "<?php echo $seven; ?>";
month[7] = "<?php echo $eight; ?>";
month[8] = "<?php echo $nine; ?>";
month[9] = "<?php echo $ten; ?>";
month[10] = "<?php echo $eleven; ?>";
month[11] = "<?php echo $twelve; ?>";
//Array starting at 0 since javascript dates start at 0 instead of 1
var mydate= new Date()
mydate.setDate(mydate.getDate())
document.write(""+month[mydate.getMonth()]+" "+mydate.getDate()+", "+mydate.getFullYear());
</script>
Sorry for not having a fiddle, I would create one but since there is some php involved I'm not sure of where to go for that. If there is something like jsfiddle that also includes php ill set that up if needed so its much easier to understand.