Tag Archive for array

Abbreviating long strings in CodeIgniter

In the process of keeping websites secure, you can end up with really long strings.  If this is generated in the code and saved to sessions/cookies/database, this isn’t a huge problem.  However, if you need to publish such an encrypted string (for instance, in an account creation confirmation URL), having massive strings not only can be a problem it also looks unprofessional.  Of course, there are plenty of URL abbreviation systems out there (bit.ly and tinyURL.com to name but two), but a lot of the time you want to keep it within your own domain.  This is where my abbreviation model comes in handy.

Read more

CodeIgniter ActiveRecord Order by Field

Following on from my post about how to extend the CodeIgniter database library, I’ve had to to find a way of ordering database results by the values in an array.  This is particularly useful if you’ve got an enum field or have specified values in a particular field and then want to output it in a particularly order.  My magical order_by_field() method solves this problem.

Read more

Extending the CodeIgniter Database Class

In the CodeIgniter user guide, it says that the Database class can’t be extended.  Which is a real pain, because it would be useful if it could be.  Well, lo and behold, the user guide is telling fibs.  The Database class can be extended.  And, what’s more, it’s fairly easy and is not a nasty hack either.

Read more

CSV Output in PHP

Comma separated values (CSV) files are a really useful way of outputting data to display in spreadsheet programs such as MS Excel.  However, they can be a bit tricky to output and get all the headers output.  So, here’s a simple class to do it.

Read more

XML to PHP Parser

XML is one of the most useful things out there and a great way of extracting data from another website.  Unfortunately, PHP can be a bit of a pain in parsing it into something usable.  The SimpleXML class has made things easier, but I prefer working with data in arrays rather than in objects which SimpleXML doesn’t really do.  I’ve written a library that parses SimpleXML into a PHP array.

Read more