Jump to content

[SOLVED] Function Files


irn3rd

Recommended Posts

Hello once again,

 

I've heard about function files that you call them from a  separate file to use in a webpage.

 

I found this open source php clock and i was wondering how i would do it in a function file because its a long code.

 

http://www.shearersoftware.com/software/web-tools/clock/clock-sample.php

 

That is the live edition of the code. and just save the page to get it on your local system.

 

Sorry if you cant make sense of it its just me.

 

Many thanks

irn3rd

Link to comment
https://forums.phpfreaks.com/topic/114516-solved-function-files/
Share on other sites

Actually, that's javascript. :)

 

And all you would have to do would be to save the javascript into a .js file, then include that in your header then call the function how they have and you should be set.

 

EDIT: My bad, reading it... Seems there is PHP in there. Sorry.

 

EDIT 2: Okay, I've uploaded the Javascript file that you need to include, since that was so big. Here is how you'd implement it.

 

<?php
/*** Clock -- beginning of server-side support code
by Andrew Shearer, http://www.shearersoftware.com/
v2.1.2-PHP, 2003-08-07. For updates and explanations, see
<http://www.shearersoftware.com/software/web-tools/clock/>. ***/

/* Prevent this page from being cached (though some browsers still
   cache the page anyway, which is why we use cookies). This is
   only important if the cookie is deleted while the page is still
   cached (and for ancient browsers that don't know about Cache-Control).
   If that's not an issue, you may be able to get away with
   "Cache-Control: private" instead. */
header("Pragma: no-cache");

/* Grab the current server time. */
$gDate = time();
/* Are the seconds shown by default? When changing this, also change the
   JavaScript client code's definition of clockShowsSeconds below to match. */
$gClockShowsSeconds = false;

function getServerDateItems($inDate) {
return date('Y,n,j,G,',$inDate).intval(date('i',$inDate)).','.intval(date('s',$inDate));
// year (4-digit),month,day,hours (0-23),minutes,seconds
// use intval to strip leading zero from minutes and seconds
//   so JavaScript won't try to interpret them in octal
//   (use intval instead of ltrim, which translates '00' to '')
}

function clockDateString($inDate) {
    return date('l, F j, Y',$inDate);    // eg "Monday, January 1, 2002"
}

function clockTimeString($inDate, $showSeconds) {
    return date($showSeconds ? 'g:i:s' : 'g:i',$inDate).' ';
}
/*** Clock -- end of server-side support code ***/
?>
<html>
<head>
<title>Clock</title>
<meta name="template" content="none">
<script language="JavaScript" type="text/javascript" src="clock.js"></script>
</head>

<body bgcolor="#FFFFFF"
    onload="clockInit(clockLocalStartTime, clockServerStartTime);clockOnLoad();"
    onunload="clockOnUnload()">
<div id="ClockTime" style="position: absolute; left: 406px; top: 28px;
    width: 200px; height: 20px; z-index: 11; cursor: pointer"
    onclick="clockToggleSeconds()">
  <p><?php echo(clockTimeString($gDate,$gClockShowsSeconds));?></p>
</div>
<div id="ClockBkgnd" style="position: absolute; left: 406px; top: 28px;
    width: 200px; z-index: 10">
  <p> <br>
  <?php echo(clockDateString($gDate));?></p>
</div>
<p><i>Click on the time to show or hide seconds.</i></p>
</body>
</html>

 

Then just download the attached file and make sure its in the same directory and it SHOULD work fine.

Remember to unzip it. :)

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.