Category: Software Development
-
PHP’s /e modifier is deprecated, use preg_replace_callback instead
I’ve discussed the use of preg_replace_callback in the past in regard to passing variables to anonymous functions but never touched on how to use preg_replace_callback or the fact that the /e modifier has been deprecated in PHP 5.5+. Even though /e still works in PHP 5.5 in the near future…
-
Transactions with PHP Data Objects (PDO)
PHP Data Objects (PDO) is arguably the best database abstraction layer available in PHP. It provides a consistent interface across multiple datasources (MySQL, PostgreSQL, et cetera) and helps boost your site’s security by way of prepared statements. It even supports transactions which we’ll be taking a look at here. Database…
-
How to zero fill a number with PHP
Zero filling (or zero padding) is when you pad a value on the left side to a specific length. This is something you will commonly see in database schemas for integer columns. But what if we’re not working with data that’s already zero filled by a database? All we have…
-
The importance of code editor proficiency
Hi, my name is Josh and I am a Vim addict. I have been for quite a while now, nearly 15 years by my estimates. I love everything about it but in all honesty, I have only really started to get “good” with it in the last couple of years….
-
How to get keys from an associative array in PHP
One of PHP’s most powerful features are arrays and the multitude of functions available to interact with and manipulate them. Arrays can be indexed by integers as well as string, known as an associative array. Instead of looping through the array with foreach and assigning the key to another array,…
-
Passing variables to anonymous PHP functions
The other day I ran into a situation (first time, it seems) where I needed to access a variable inside of an anonymous function inside of preg_replace_callback(). My first thought, even though it went against my better judgement was to simply define the variables as global inside of the function….
-
Opt-out responsive design using LESS
I liked Chris Coyier’s post Opt-Out Responsive Design? but really didn’t like the idea of having to qualify all of my selectors with a parent class to indicate that we should be using the responsive version of the site. I do favor serving the user a single stylesheet instead of…
-
Using list() with foreach() in PHP
Continuing my showcasing of all of the awesomeness in PHP 5.5 that I am discovering since my upgrade from 5.3, let’s discuss using the the list() function inside of a foreach() block. Have you ever had a situation where you are looping through a multi-dimensional array and the array is…
-
“Failed to open page” on Windows Phone 8
I ran into an issue a few days ago after pushing some hand rolled “infinite scroll” logic to my sites. One of my users reported getting the “Failed to open page” error on her Windows Phone 8 using UC Browser, some aftermarket browser I had never heard of. The rest…
-
How to use Generators in PHP
Support for generators (via the yield keyword) has been added to PHP 5.5 and allows you to create simple iterators without the use of the Iterator interface. What’s this all mean? It boils down to overhead, generators use less memory than an implementation of the Iterator interface or simply creating…