Period: Time range API for php

Date/time programming is one of the tricky aspects of software development. Although inherently not complex in itself, coding date/time algorithms can be a subtle source of bugs. Especially in web development a feature such as payment subscription processing that ranges from days to weeks to months can get complex quickly. Also such kind of scenarios require additional features like auto renewal, scheduled email alerts to subscribers etc. Such kind of features require good date/time handling algorithms and libraries that handle such chores are always welcome.
Read More

Splitting a text on word boundaries

Substring extraction of a long piece of text is a common element in web design, mostly in blogs and other CMS for displaying excerpts. The most common way to show an excerpt is to get n number of characters of the text, or n number of words. We will explore both ways. In PHP we frequently use the substr function. However, substr or any of its variants does not split the text at word boundaries, keeping broken words hanging at the end. There are many ways we can prevent this, using some text adjustments. A simple one is shown here.
Read More

Building a Graph data structure in PHP

undirected graphGraphs are one of the most frequently used data structures,along with linked lists and trees. In a recent PHP project I needed to build a Graph structure to analyze some interlinked urls. The problem was of a simple nature, so rather than writing my own code, I went with the one available in the Pear repository.

The Pear Structures_Graph package allows creating and manipulating graph data structures. It allows building of either directed or undirected graphs, with data and metadata stored in nodes. The library provides functions for graph traversing as well as for characteristic extraction from the graph topology.
Read More