Tagphp

On $matches in preg_match functions

I’ve seen many people define an empty $matches variable before using it in preg_match and preg_match_all functions in PHP. I’ve done it myself, and I was quite surprised to learn that you don’t really have to — even if there’s no match, you will not get an undefined variable notice.

Reminder: Don’t Use the Short PHP Open Tag

Jetpack 2.0.1 was released last night, immediately followed by 2.0.2, which fixed a fatal error on some hosts, caused by a short PHP open tag. So here’s a reminder: never use the short form of the PHP opening tag: <? _doing_it_wrong(); ?> Always use the long form: <?php _doing_it_right(); ?> If your grep can do Perl regular expressions, you can search your entire codebase with a...

Don’t Be Shy to Use sprintf with WordPress

Don’t be shy to use the printf and sprintf functions with WordPress. It makes code much easier to read. Take a look at the following examples. echo '<a href="' . get_permalink() . '" class="link">' . get_the_title() . '</a>'; It looks quite dirty and it’s very easy to miss a quote or double-quote. Here’s one that looks a lot cleaner and easier to read: printf( '<a...

How To: Show Off Your Social Counters in WordPress

You know it’s all about social these days, and this post is about showing off how social you are on your WordPress website. I’m sure you’re using tonnes of social networks and all of them have friends, followers, fans and subscribers metrics, but let’s start from simple: Twitter, Facebook and RSS. We’ll write code in this post, and you may ask me why. Of course there...

Happy 2011: In 10+ Different Programming Languages

The end of the year 2010 is near so I’ve prepared this post for all you coders, developers and other geeks. You know when you build applications (especially web applications) you often leave a copyright notice on every page saying “Copyright 2010, All Rights Reserved” or whatever? Right, but what developers tend to forget is that time passes by and that they have to go back and...

October Quickie: A Little Bit of Everything

Well yeah, it started snowing today here in Moscow, but this post is not about snow. I remember I’ve done some quickie before, but couldn’t find it. Perhaps it was something I mentioned inside the blog post with a different title. But anyways, this is a short roundup of what I’ve been up to lately. Let’s start with Python.. After reading a very popular book called...

A 60-Day Trip from PHP to .NET MVC

This is quite an unusual post I guess, something that came in to my mind a few days ago. If you’re familiar with my biography you know I’m in love with php, unix and the open source world. The reason I’m writing this post (or maybe set of posts) is that I found quite a good client, who’s very strict about technology, so the very basic website that they’re looking for...

WordPress and Magic Quotes

This is crazy, and based on a post called WordPress and PHP magic quotes: you want to run me crazy! by Stefano Lissa. I’m writing a plugin prototype for WordPress that uses the new Facebook Graph API to post stuff to my wall on Facebook (upcoming blog post). The original Facebook PHP SDK comes in very handy when working with the Facebook API, and I had quite some fun using it, but...

Counting Facebook Fans in PHP: The Graph API Way

In a previous blog post called How to Count Facebook Fans in PHP I’ve shown a code snippet of how to count the number of fans on a fan page using PHP. Times have changed, the Graph API has been introduced, and due to some responses I introduce here the new way of retrieving your fans count using the new Graph API and php. Before you copy and paste, flush my comments with ‘my code is...

How to Generate Quality Data for MySQL

We all had fun with the World Database, Sakila and the others when learning MySQL (see Example Databases), but it sometimes isn’t enough to run certain experiments, benchmarks within your own schema. Of course you could write a script that would generate junk data based on your column types and populate your database with a few thousand entries, but as it turns out, Benjamin Keen already...