UltraMega Tech.
23Jun/090

What’s new in PHP 5.3?

With last week's announcement of RC4, the final release of PHP 5.3 is imminent. So what can we expect in this version? Here I'll outline the biggest and most interesting changes and additions. This is definitely not exhaustive since there are tons of minor changes and improvements in this version, but these are some of the ones I found interesting.

Tagged as: , Continue reading
16Jun/094

5 Tips for Writing Cleaner PHP Code

There are many benefits to writing clean code for any project, no matter how small. The most obvious benefit is that it is easier for you to read and edit, especially when you come back after a long break. This is even more important when someone else comes in to modify your code. The importance of clean code becomes most apparent when you need to find an error, especially a syntax error. In the end, cleaner code means less time reading and more time coding!

These are 5 tips that I use and recommend. I know there are plenty of lists like this, but I hope you learn at least one new trick...

12Jun/090

Upgraded to WordPress 2.8

We've upgraded to WordPress version 2.8! Many improvements have been made in this release, as well as hundreds of bug fixes. Along with overall speed and optimization in the admin interface, the major improvements are:

  • Ability to browse the theme directory and install themes directly from the admin interface
  • Further customization of the admin interface such as changing the number of columns and items
  • New Widget interface that allows you to save the settings of inactive widgets
  • Code syntax highlighting and function reference in the theme and plugin editors
  • Support for timezones and DST adjustments
  • And much more!

See the full list of changes.

3Jun/097

Snippet: Converting Seconds to Readable Time (PHP & JS)

Sometimes, you might need to convert an integer representing seconds into a format that is easier to read. These functions can be used to turn a number of seconds into a simple format of HH:MM:SS, with leading zeros (ex. 15272 = 04:14:32). This can be used for countdown scripts, which is why I also include both a PHP and a JavaScript version.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function formatTime($secs) {
   $times = array(3600, 60, 1);
   $time = '';
   $tmp = '';
   for($i = 0; $i < 3; $i++) {
      $tmp = floor($secs / $times[$i]);
      if($tmp < 1) {
         $tmp = '00';
      }
      elseif($tmp < 10) {
         $tmp = '0' . $tmp;
      }
      $time .= $tmp;
      if($i < 2) {
         $time .= ':';
      }
      $secs = $secs % $times[$i];
   }
   return $time;
}
29May/091

Snippet: Autoloading Objects (PHP 5)

When writing the PHP that powers TempServers, I wrote the core functions into classes for better organization and efficiency. To make things further organized, each class is stored in individual source files, no matter how small. The problem here is keeping track of which classes are used where, in order to include the appropriate source files. Fortunately, PHP 5 offers a solution: autoloading.

This comes in the form of the __autoload function which automatically gets called if a class is called that does not exist. Here's what it looks like:

function __autoload($class) {
    require_once(strtolower($class) . '.class.php');
}

Usage

  1. Place each PHP class in individual files named after the class followed by .class.php (Example: class MyClass goes in a file named myclass.class.php).
  2. Include the code snipped above into any file that might use one of your classes.

For more details, check out the PHP manual: http://www.php.net/manual/language.oop5.autoload.php

28May/090

Follow us on Twitter

You can now follow UltraMega Tech on Twitter: http://twitter.com/UltraMegaTech

We'll keep you up to date on any projects we're working on as well as any useful information that we find. New blog posts will also be posted there.

Tagged as: No Comments