PHP last day of a month

18 02 2009

This is a nice little snippet to get the first and last dates of a particular month

$Month = 2;
$Year = 2009;
if($Month < 10 && strlen($Month) == 1)
{
$Month = "0".$Month;
}
$MonthStart = $Year."-".$Month."-01"; // first day of a month
$MonthEnd = $Year."-".$Month."-".date("t", strtotime($MonthStart)); // last day of a month

This does come with the caveate, however, that there is no validation on $Year and $Month. If you have $Month = 15 or $Year = “house” then you will have problems, a more advanced method is a topic for another post perhaps! :)





Javascript Causes Internet Explorer cannot open the Internet site

13 02 2009

A nightmare situation… Your page works fine in most browsers, you test it in Internet Explorer 7 and just as it looks like everything is working fine you get this:

Internet Explorer cannot open the Internet site

Internet Explorer cannot open the Internet site

Bam! Right in the kisser!

I narrowed down the problem down to this:

<script type=”text/javascript”>
jQuery(‘#Calendar1 *’).tooltip();
</script>

Which is a jQuery plugin for adding tooltips. Its very good, but it looked like IE doesn’t like it!

Don’t despair though, it is just that IE does not like being rushed, adding an event handler to make the function wait until the entire page is ready fixes the problem

<script type=”text/javascript”>
jQuery(document).ready(function () {
jQuery(‘#Calendar1 *’).tooltip();
});
</script>

Moral of the story, don’t rush IE! and keep your javascript unobtrusive!





PHP tidy extension is loaded but not working

13 02 2009

The other day we had trouble getting PHP tidy to work on Red Hat Fedora Core 9. Especially frustrating was that we would get an error message like this one:

Fatal error: Class ‘tidy’ not found in Path/to/file.php on line 9

And of course this is made worse by the fact that extension_loaded(“tidy”) shows that the Tidy extension is loaded! So the Tidy extension being loaded, but the class not existing was a bit puzzling to say the least.

The long and short of it was that we came up with this methodology for setting up the tidy extension on Red Hat:

  1. Run commad pecl install tidy to get the latest version of tidy
  2. Run yum install libtidy to get the lib that the extension depends upon
  3. Add the line extension=tidy.so to your php.ini (or a create a tidy.ini in your php extensions ini folder – possibly /etc/php.d/)
  4. Run yum install php-tidy to install the extension that get tidy.php working together (This is probably the step that is missing if you are getting the above error)
  5. Restart apache:  /etc/init.d/httpd graceful on our system

And that was all there was to it! Not a very exciting blog post, but hopefully useful to someone :)








Follow

Get every new post delivered to your Inbox.