Useful PHP Functions

Every so often I sit down and try to either fix a problem on velospace or code up another feature. When putting new features together it usually takes a few hours to design, code, troubleshoot, and launch. During the coding process php.net ends up being one of the most common resources I turn to.

A few gems from the PHP manual that have saved me a whole lot of time and headaches:

  • strip_tags() - easily remove HTML from user strings put on display
  • strtotime() - simply convert a plain English time and date - like June 30, 2001 - into a Unix timestamp. This function is incredibly useful for standardizing and sharing timestamps between Drupal, which uses Unix timestamps, and Vanilla, which uses plain English timestamps.
  • db_fetch_object() - grab a database result as a PHP object for easy references, e.g. $forSale->price, $forSale->title, and $forSale->description. Objects make grabbing and displaying data from a database infinitely easier.

PHP is nearly 15 years old and there are very few problems people haven’t already solved using it. Its a great tool to have because the implementation is simple and relatively straight forward.

- Greg