Use PHP_Compat to use more recent PHP functions in old versions of PHP

As stated in my previous post, we needed to stick to PHP 5.2 rather than upgrade to a more recent version. One of the many downsides of this other than for security reasons is that you miss out on a large number of more useful functions.

In our case we missed the “str_getcsv()” function when reading in a .CSV file line by line. A really quick way to get around this, with or without using PEAR, was to download PHP_Compat, which includes a huge number of compatible functions from later versions of PHP.

If you have PEAR installed you can simply run the following to enable the functions:

pear install PHP_Compat

But if you are like us, running a version of Linux without PEAR installed by default you can just download the library directly. Once downloaded, just place in your web application directory (or elsewhere depending on configuration) and use a require_once() command in each PHP script for each function that you need, e.g.:


If you are on shared hosting or cannot get a more recent version of PHP, this library is a lifesaver.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>