PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function pageClock()
{
// set clocks size and color
$tcolor = '#009999';
$tsize = '3';
// body tags may be removed if called in a PHP page that already echoes HTML
echo '
<body>
<div align="center">
<font size="'.$tsize.'" color="'.$tcolor.'"><b>
<span id="clock">
<SCRIPT LANGUAGE="JavaScript">
<!--
function getTheDate(){
';
// PHP Date function
$currDate = date("l, F j, Y");
$dn = date("A");
// JS Date string makes page update in real-time
echo '
var myDate=new Date()
var date ="'.$currDate.'"
var hours=myDate.getHours()
var minutes=myDate.getMinutes()
var seconds=myDate.getSeconds()
var dn="'.$dn.'"
';
//put the display together
echo'
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
var cdate=date+" | "+hours+":"+minutes+":"+seconds+" "+dn
';
echo '
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getTheDate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getTheDate()",1000)
}
window.onload=goforit()
// End -->
</script>
</span>
</b>
</font>
</div>
</body>
';
}
The problem I ran into was that the "real-time" update of the seconds didn't work because I was unsure of how to translate the PHP date() function to a model like the JS date() function which allows me to dynamically go get the date. I suppose the question is: "Will PHP do the same thing that the JS will if we modify the code to be:
echo '
'.$myDate=new Date().'
var date ="'.$currDate.'"
'.$hours=$myDate.getHours().'
'.$minutes=$myDate.getMinutes().'
'.$seconds=$myDate.getSeconds().'
var dn="'.$dn.'"
';
I am a bit reluctant to break the code without knowing if it will work or not
It looks like you're trying to just mix up javascript and php as a combined language. It can't be done that way but you can combine the two if you think about what the output of the php will do that javscript.