Notes on Quotes in PHP

Something I’ve noticed from php developers regardless of experience level is the misunderstanding of when to use single quotes (‘) or double quotes (“) in their strings. If you’re coming from a language such as Javascript, the quote style you use is really a matter of preference. PHP is different. Technically, either will appear to work all the same but there is a design intention to their proper use and misusing them can make for ugly code and also take a (albeit, probably small) performance hit.

Let’s look at the following code:

$x = 'string';
echo "This $x is an example.";

Read more…

WordPress Plugin: WebStats

This is a WordPress plugin that collects information on visitors’ web browser and operating system and display totals for each type in a bar graph – see the screenshot.

Tracks the most common browsers (Chrome, FireFox, Safari, IE, Opera) and operating systems (Windows, Mac, Unix, iOS, Android) and tallies a total for each type. The information is then presented in a bar graph in the admin page.

Currently, only the entities listed above are tracked. Version differentiations are not tracked – so, Windows is Windows regardless if it’s Windows 95 or Windows 7.

  Wordpress CCO WebStats Plugin 1.0.0 (192.5 KiB, 70 hits)

CSS, Minification… and You.

If you run Yahoo’s YSlow or use FireBug to display page load times, one of the recommendations to increase your site’s performance is to optimize CSS and JavaScript transfers by “minifying” them.

Minification is the process of stripping out any of the unnecessaries that developers add to their files to make them easier to read and prettier to view. Things like white space (spaces), comment characters, line breaks, tabs, etc.

Example,

Original (279 bytes):

body {
font-family: helvetica, arial, sans-serif;
color: block;
line-height: 1.2em;
}

/* make divs centered */
.center {
display: block;
margin: 0 auto;
}

#box {
border: 1px solid #000;
padding: 15px;
margin-top: 5px;
}

Minified (165 bytes):

body{font-family:helvetica,arial,sans-serif;color:block;line-height:1.2em}
.center{display:block;margin:0 auto}#box{border:1px solid #000;padding:15px;
margin-top:5px}

The original CSS is now 41% smaller after minification! For low traffic websites, saving 114 bytes on a page load isn’t significant but for high volume sites, 1000 page loads (ignoring caching for the sake of argument) is about 111K of less data to be transferred. Now imagine a site like amazon.com getting millions of hits – the bandwidth savings becomes quite significant.

So, web developers. Reduce your bandwidth footprint and minify your CSS and Javascript files! You can use the free tool below to do so:

CSS/JavaScript Minify-O-Matic!