-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
62 lines (55 loc) · 1.14 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
include("constants.php");
function month($n)
{
$timestamp = mktime(0, 0, 0, $n, 1, 2005);
return date("M", $timestamp);
}
function validateDate($input)
{
preg_match('/\d{2}\.\d{2}\.\d{4}/',$input,$output); // this matches 2decimal.2decimal.4decimal and puts it in $output
if ( count($output) == 1 )
{
// there should be exactly 1 value in the array
return $output[0];
}
else
{
return "error";
}
}
function getRandomNewsItem($rssObj) {
$num = rand(0,(count($rssObj->items)-1));
$title = $rssObj->items[$num]['title'];
$link = $rssObj->items[$num]['link'];
$itemSum = $rssObj->items[$num]['description'];
return array("title"=>$title,"link"=>$link,"itemSum"=>$itemSum);
}
function writeDate($m,$d,$y)
{
if ( $m == "error" )
{
echo "$m";
}
else
{
echo "$m $d, $y";
}
}
function getFileName($day,$month,$year)
{
return pad($day, 2) . "." . pad($month, 2) . "." . pad($year, 4);
}
// This function pads a number to a fixed length by
// adding leading zeroes.
// e.g. "3" padded to length "2" returns "03"
function pad($s, $n)
{
$r = $s;
while ( strlen($r) < $n )
{
$r = "0" . $r;
}
return $r;
}
?>