Welcome to WebmasterWorld Guest from 54.158.228.55

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

why did this script stop working?

displays open hours

     
6:38 pm on Nov 2, 2012 (gmt 0)



I recently found this script to display daily open hours (which change often) on my website. It worked perfectly for two weeks (in October) then just stopped working on Nov 1. Any thoughts on why?

There were no server changes during this time. I don't get an error message it just doesn't display the hours. It does still display the current date. My hours table (libraryhourstable.txt)seems to be properly formatted.



<?php
// This routine at the top getts the path to the root of your web site on your server and setts it as a variable
$fullpath=realpath(basename(getenv("SCRIPT_NAME")));
$fullpath=str_replace("\\","/",$fullpath);
$localpath=getenv("SCRIPT_NAME");
$rootpath = str_replace($localpath, "", $fullpath);
?>

<!-- This is where you put the content -->
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', '1');

// Explode text file and store each row of the file into the array elements
function explodeRows($data) {
$rowsArr = explode("\n", $data);
return $rowsArr;
}

// Explode the columns according to tabs
function explodeTabs($singleLine) {
$tabsArr = explode("\t", $singleLine);
return $tabsArr;
}

// Open the text file and get the content
$filename = $rootpath . "/m/libraryhourstable.txt";
$handle = fopen($filename, 'r');
$data = fread($handle, filesize($filename));
$rowsArr = explodeRows($data);
$today = date("n/j/Y");

// Make array containing today and seven other dates
echo "<div id=today><p class=center><b>Today:</b> " . date("l n/j/Y") . "<br>\n";
for($i=1; $i<=6; $i=$i+1)
{
$days[$i] = date("n/j/Y", strtotime("+$i day"));
//echo $days[$i] . " the days<br />";
}

// Display content which is exploded by regular expression parameters \n and \t
for($i=0;$i<count($rowsArr);$i++) {


$lineDetails = explodeTabs($rowsArr[$i]);
if ($lineDetails[1]==$today && $lineDetails[4]=="Closed") {
$j=0;
echo "\n <span class=redtext><b>" . " " . $lineDetails[4] . "</b></span></p></div>\n<ul id=hourslist>\n";
} elseif ($lineDetails[1]==$today) {
$j=0;
echo "\n<big><b>Hours:" . " " . $lineDetails[4] . " - " . $lineDetails[5] . " </b></big> \n";
if (trim($lineDetails[8])!=="Closed"){
echo "<br /><span class=latehour>Late Room until: " . $lineDetails[8] . "</span>\n";
}
echo "</p>\n<ul id=hourslist>\n";
} elseif (in_array($lineDetails[1], $days) && $lineDetails[4]=="Closed") {
$j=$j+1;
if ( $j&1 ){
$oddoreven="hoursodd";
} else {
$oddoreven="hourseven";
}
echo "<li class=" . $oddoreven . "> <b> <span class=redtext> " . $lineDetails[3] . " : " . " " . $lineDetails[4] . "</span></b></li>\n";
} elseif (in_array($lineDetails[1], $days)) {
$j=$j+1;
if ( $j&1 ){
$oddoreven="hoursodd";
} else {
$oddoreven="hourseven";
}
echo "<li class=" . $oddoreven . "> <b> " . $lineDetails[3] . ": </b>" . $lineDetails[4] . " - " . $lineDetails[5];
if (trim($lineDetails[8])!=="Closed"){
echo "<br /><span class=latehour>&nbsp;&nbsp;&nbsp;Late Room until: " . $lineDetails[8] . "</span>\n";
}
echo "</li>\n";
}
}

echo "</ul>\n ";
?>



Thanks in advance.

BTW, I'm a total php novice, though I'm trying to learn.
8:54 pm on Nov 2, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



:: peering into crystal ball ::

Your dates are now arriving at the function with a leading zero. Previously they arrived with a leading non-zero.

Been there. Done that.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month