Tag: PHP
-
How to connect to MongoDB using PHP
I’ve previously discussed installing the MongoDB module but have yet to touch on how to actually do anything past the install. The first thing to do is to connect to the MongoDB server. This can simply be done like this: $client = new MongoClient(); This will connect to the default…
-
Stop Accommodating Shortcomings
I came to a very liberating conclusion the other day. I need to stop fucking around with MySQL, or any other RDBMS, and fully embrace a NoSQL server as my primary data store. I’ve been a huge fan of Redis for quite some time but the fact that everything lives…
-
How to merge two sorted PHP arrays without array_merge() or sort()
I’ve had this question come up a few times in the past on interviews, how would you merge two sorted arrays and keep their sort order intact? The easy / PHP answer is to simply use array_merge() and then sort() the resulting array. Technically this works but the whole point…
-
Visibility in PHP
Visibility of functions and properties is very important when you are attempting to lock down certain aspects of an object. In PHP there are three levels of visibility, public, private and protected. Let’s take a look at what each one means. Public Public is the easy one. It’s the default…
-
Simple PHP i18n internationalization and localization class
As sites and system grow and scale, the need for internationalization and localization (i18n and L10n respectively) of content becomes a necessary task. There’s not much to it on the surface, you need to be able to serve up the same content in different languages. This includes abstracting out words…
-
Debugging Invalid XML in PHP
SimpleXML with all of it’s faults is still a great way to interact with XML. Most of it’s shortcomings are related to debugging and how it handles invalid XML is no exception. Let’s take a look at what happens when we load an invalid XML string: $xml = ” <?xml…
-
Upgrade from PHP 5.3 to PHP 5.6 on Ubuntu 12.04 LTS
Last week I posted a call to action to help sway Ondřej Surý into continuing to support Ubuntu 12.04 LTS with his amazing PPA for the latest and greatest PHP versions. Ondřej was kind enough to take the time to backport the PPA and without ado, here’s how to get…
-
Call to Action: PHP 5.6 on Ubuntu 12.04 LTS
I’m going to take a break from posting code snippets and how-tos to draw attention to the fact that PHP 5.6 may not be coming to Ubuntu 12.04 LTS by way of Ondřej Surý’s amazing PPA. Yes, you can still compile PHP from source, but as you may already know,…
-
Upgrade to PHP 5.6 on Ubuntu 14.04 LTS
PHP 5.6 is finally here and if you’re on Ubuntu 14.04 LTS you’re stuck with an older version of PHP. If you want to take advantage of the new awesomeness, you can do so very easily thanks to a PPA. If you’ve never added a PPA before, you will want…
-
Fizz Buzz in PHP
Fizz buzz is a fairly common screening question to help sniff out non-programmers during the interview process. The task is to print out numbers 1 through 100 but for multiples of 3 print out “Fizz” instead of the number and for multiples of 5 print “Buzz” instead. If the number…