PHP - Install YAML Support

If you need to generate YAML files from PHP (perhaps for Docker Compose), then it is probably easiest to install the YAML Data Serialization PECL package. Thist tutorial will show you how to do that on Ubuntu 14.04. Installation Run the following bash script: sudo apt-get install php5-dev php-pear…

Read this article

PHP Gotchas and Tips

Here are some PHP observations that I have been caught out with and am posting so I don't get caught again. This post will grow over time as I find more bite-size nuggets. Gotcha: Array Merge Guess what the output to this code will be: <?php $lookup_table = array(…

Read this article

PHP Time/Date Cheatsheet

Converting User Input $timestamp = strtotime("01/01/1999"); $timestamp = strtotime(915148800); $timestamp = strtotime("1st January 1999"); You now have the unix timestamp (number of seconds as an integer, since 1st January 1970) PHP considers date strings with - to be English, and dates with / to be American. # This is the…

Read this article

PHP - Converting Data for Google Charts

I find it annoying that for a line graph, Google wants the data in this format (javascript): var data = google.visualization.arrayToDataTable([ ['Year', 'Sales', 'Expenses'], ['2004', 1000, 400], ['2005', 1170, 460], ['2006', 660, 1120], ['2007', 1030, 540] ]); In PHP form this is equal to the following (before we run JSON…

Read this article

Laravel Route Jenkyness

If you start a new Laravel 5 project, you may notice that Netbeans doesn't know what certain items are. For example if you open the routes file at /app/Http/routes.php you will see the following: Route::get('/', function () { return view('welcome'); }); Now if you double click…

Read this article

Using Markdown in PHP Safely

You may want to allow users to perform more advanced actions when filling out a task/bug description or editing their profile description. You may want them to give them the ability to create hyperlinks, create lists, embed images, and add formatting their text. However, allowing users to enter raw…

Read this article

Install Zookeeper PHP Extension

The following tutorial will install the Zookeeper extension for PHP and has been tested on Ubuntu 14.04 and Debian 8. Steps Firstly, we need to manually install Zookeeper. You can go here to grab the latest version/link, which at the time of writing this tutorial is 3.4.…

Read this article

Ubuntu 14.04 - Install PHP 7 From PPA

Run the script below to install PHP 7.0. sudo apt-get install python-software-properties -y sudo add-apt-repository ppa:ondrej/php-7.0 -y sudo apt-get update sudo apt-get dist-upgrade -y sudo apt-get install php7.0 -y To check your version, execute php --version and you should get output similar to: PHP 7.…

Read this article

PHP - Callbacks And Sharing Resources

Something I keep questioning myself on is whether use() passes instantiated classes by reference or creates a copy, and whether this applies to the stdClass as well. The script below demonstrates that all objects (including stdClass) are passed by reference but basic types such as integers are passed a copy.…

Read this article

Getting Started with MongoDB GridFS And PHP

By default, the MongoDB database can only store documents up to 16MB, the BSON-document size limit. This is perfectly fine for most cases, but what if you want to do something crazy, and use MongoDB as a filesystem? 16MB would not be enough for storing large media content, such as…

Read this article