<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>[Re]Encoded.com &#187; HTML</title>
	<atom:link href="http://www.reencoded.com/category/web-design/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reencoded.com</link>
	<description>Web Design and Development Tips, Tutorials and [Re]lated [Re]sources</description>
	<lastBuildDate>Tue, 24 Jan 2012 20:23:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>A Useful Addition to any Business Website</title>
		<link>http://www.reencoded.com/2008/08/05/a-useful-addition-to-any-business-website/</link>
		<comments>http://www.reencoded.com/2008/08/05/a-useful-addition-to-any-business-website/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 19:02:54 +0000</pubDate>
		<dc:creator>Anders Haig</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[time and date]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://reencoded.com/2008/08/05/a-useful-addition-to-any-business-website/</guid>
		<description><![CDATA[I&#8217;ve used this code in a large amount of business websites I&#8217;ve produced. It allows users to see at a glance whether a business is open or closed. If the time is within the specified hours, it will display an open image, if it any other time, it will display the closed image. It is [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve used this code in a large amount of business websites I&#8217;ve produced. It allows users to see at a glance whether a business is open or closed. If the time is within the specified hours, it will display an open image, if it any other time, it will display the closed image. It is easy to implement and looks great on a store hours page. It goes by the time of your server however so if your server is in a different timezone, adjust the hours accordingly. See a demo in action <a href="http://www.sustainabilitynh.com/hours.php"  rel="nofollow">here.</a></p>
<p>&lt;?php<br />
<strong>/**<br />
* Open / Closed script<br />
* Try to edit only the &#8216;$hours&#8217; array and the &lt;img /&gt; tags later on<br />
* Editing anything else could give undesired results<br />
*/</strong></p>
<p><strong>// These are the hours, correlating with the above days, in AM and PM format separated by &#8216;-&#8217;</strong><br />
$hours = array(&#8216;Sunday&#8217; =&gt; &#8216;Closed&#8217;,<br />
&#8216;Monday&#8217; =&gt; &#8216;By Appointment&#8217;,<br />
&#8216;Tuesday&#8217; =&gt; &#8217;10AM-5PM&#8217;,<br />
&#8216;Wednesday&#8217; =&gt; &#8217;10AM-5PM&#8217;,<br />
&#8216;Thursday&#8217; =&gt; &#8217;10AM-5PM&#8217;,<br />
&#8216;Friday&#8217; =&gt; &#8217;10AM-6PM&#8217;,<br />
&#8216;Saturday&#8217; =&gt; &#8217;10AM-5PM&#8217;);</p>
<p><span id="more-195"></span></p>
<p><strong>/**<br />
* Do not alter any code in this function unless you know what you are doing!</strong></p>
<p><strong>*/</strong><br />
function isOpen($hours) {<br />
$days = array(0 =&gt; &#8216;Sunday&#8217;,<br />
1 =&gt; &#8216;Monday&#8217;,<br />
2 =&gt; &#8216;Tuesday&#8217;,<br />
3 =&gt; &#8216;Wednesday&#8217;,<br />
4 =&gt; &#8216;Thursday&#8217;,<br />
5 =&gt; &#8216;Friday&#8217;,<br />
6 =&gt; &#8216;Saturday&#8217;);</p>
<p><strong>// Determine today&#8217;s weekday</strong><br />
$weekday = date(&#8216;w&#8217;);</p>
<p><strong>// Make sure that there are no errors in the formatting</strong><br />
if (!isset($days[$weekday])) {<br />
return false;<br />
} else if (!isset($hours[$days[$weekday]])) {<br />
return false;<br />
}</p>
<p><strong>// Get the current day in string format</strong><br />
$day = $days[$weekday];</p>
<p><strong>// Determine if hours are given</strong><br />
if (!is_numeric($hours[$day][0])) {<br />
return false;<br />
}</p>
<p><strong>// Get the hours</strong><br />
$hours = explode(&#8216;-&#8217;, $hours[$day]);</p>
<p><strong>// Again, make sure that there are no errors in the formatting</strong><br />
if (sizeof($hours) != 2) {<br />
return false;<br />
}</p>
<p><strong>// Calculate the given hours</strong><br />
foreach ($hours as $index =&gt; $hour) {<br />
<strong>// Check the formatting of the hours</strong><br />
if (!preg_match(&#8216;~^(\d{1,2})(A|P)M$~s&#8217;, $hour, $time)) {<br />
return false;<br />
}</p>
<p><strong>// Get the raw hour</strong><br />
$hour = (int)$time[1];</p>
<p><strong>// Handle AM and PM times</strong><br />
switch ($time[2]) {<br />
case &#8216;P&#8217;:<br />
if ($hour != 12) {<br />
$hour += 12;<br />
}<br />
break;<br />
case &#8216;A&#8217;:<br />
if ($hour == 12) {<br />
$hour = 24;<br />
}<br />
break;<br />
default:<br />
return false;<br />
}</p>
<p><strong>// Ensure that the time is valid</strong><br />
if (($hour &lt;= 0) || ($hour &gt; 24)) {<br />
return false;<br />
} else if ($hour == 24) {<br />
$hour = 0;<br />
}</p>
<p>$hours[$index] = $hour;<br />
}</p>
<p><strong>// Determine if the business is open</strong><br />
$now = date(&#8216;G&#8217;);</p>
<p>if (($now &lt; $hours[0]) || ($now &gt;= $hours[1])) {<br />
return false;<br />
}</p>
<p>return true;<br />
}<br />
?&gt;</p>
<p>The next section goes wherever you&#8217;d like the code to appear in your website.</p>
<p>&lt;?php<br />
if (isOpen($hours)) {<br />
<strong>// Opened image</strong><br />
echo &#8216;&lt;img src=&#8221;images/open.gif&#8221; alt=&#8221;Open&#8221; title=&#8221;Open&#8221; /&gt;&#8217;;<br />
} else {<br />
<strong>// Closed image</strong><br />
echo &#8216;&lt;img src=&#8221;images/closed.gif&#8221; alt=&#8221;Closed&#8221; title=&#8221;Closed&#8221; /&gt;&#8217;;<br />
}<br />
?&gt;</p>
<p>Feel free to edit and use this code as you please. Download the PHP file here: <a href="http://reencoded.com/wp-content/uploads/2008/08/hours.zip"  title="PHP Hours File" rel="nofollow">PHP Hours File</a></p>
<script type="text/javascript">(function() {var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];s.type = 'text/javascript';s.async = true;s.src = 'http://widgets.digg.com/buttons.js';s1.parentNode.insertBefore(s, s1);})();</script><a href="http://digg.com/submit?url=http%3A%2F%2Fwww.reencoded.com%2F2008%2F08%2F05%2Fa-useful-addition-to-any-business-website%2F"class="DiggThisButton DiggCompact"   rel="nofollow"></a>]]></content:encoded>
			<wfw:commentRss>http://www.reencoded.com/2008/08/05/a-useful-addition-to-any-business-website/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

