Part of the program I’m writing had to check if given hour falls between two hours, for example, if 1 pm is between 5 am – 5 pm, or 11 pm is between 9 pm – 9 am. I couldn’t find snippet on the net so I wrote my own function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| /**
* Checks if given hour is between two hours (in 24 hour format)
* if $hour is not specified it defaults to current hour
*
* @return bool
* @param integer $start
* @param integer $end
* @param integer $hour[optional]
*/
function is_between_hours($start, $end, $hour = NULL)
{
$hour = (is_null($hour)) ? date('G') : $hour;
if ($start == $end) return TRUE;
if ($start > $end) return (($hour < $start) && ($hour > $end)) ? FALSE : TRUE;
else return (($hour >= $start) && ($hour <= $end)) ? TRUE : FALSE;
} |
If you know better way of doing it or have a question – please leave a comment.
Just noticed this morning that my SitePoint Forum posts have rel=”nofollow” attribute added to signature links. Not cool. I always thought SitePoint was dofollow forum. After a little digging I found this post: Fluff posting on the forum. Apparently change was made on Nov 17th 2008 and SitePoint now requires at least 100 posts to have signature links without rel=”nofollow” attribute.
Yesterday I had to move WordPress directory for a client (don’t ask why). After following basic instructions outlined in Codex Moving WordPress page I had only one problem left – missing images in blog posts. In database they are saved using full path and were pointing to the old directory.
I came up with following query to fix the problem:
UPDATE wp_posts
SET guid = replace(guid, 'http://website.com/dir1/', 'http://website.com/dir2/')
WHERE post_type = 'attachment'
It looks in your wp_posts table and and replaces paths to uploaded files, in this case case – from “http://website.com/dir1/” to “http://website.com/dir2/”.
Use at your own risk!