Life of a web developer

February 4, 2011

External: Book Review – PHP 5 Social Networking

Filed under: External, Reviews — Ole Aass @ 9:21 am

I just read a very good review article by Chris Hartjes on the book PHP 5 Social Networking. It’s on point, not to long and it’s reveals just enough to trigger the interest for the book. No spoiler alert what so ever 😛

It’s also rare to find a book that teaches you something while you are actually building something. If you were to actually sit down and type in every single code example, my guess is that you would have 90% of a completely working site. Building upon all that stuff you’ve learned by following the book along, it seems to me it would be easy to get it to 100%.

Just look at the sort of stuff you learn about:

  • the Model-View-Controller pattern
  • creating effective templates
  • proper use of a registry object
  • planning of relationships between data (along with use of binded parameters in your DB queries via PDO
  • post-coding tasks like deployment and figuring out how to get data from development into production

Check out the original article here:



February 2, 2011

External: 27 ways to be a better PHP developer

Filed under: External, PHP — Tags: , , , — Ole Aass @ 12:17 pm

LornaJane posted on her blog today a great 46 page slide covering 27 essential ways on how to be a better php developer. It’s not a “best practice” coding style article, but it has focus on the higher aspects on how to be better.

Some points covered in the slide is:

  • Participate in communities
  • Focus on relationships
  • Keep learning
  • Challenge yourself by leaving your comfort zone

Even though the title of the article is “27 ways to be a better PHP developer”, it is absolutely an article that refers to any developer, no matter what language.


February 1, 2011

My latest RSS subscriptions and twitter follow’s

Filed under: External, Misc. — Tags: , , , — Ole Aass @ 2:47 pm

I finally started following some RSS feeds now, and added a few new users to my twitter following list. I’ve been extremely lazy on this forever but I thought that now it was about time to get myself together and start reading up, and learn more instead of just knowing what I know.. That is how I’ve done it until now since I’ve only used PHP for hobby. But now that I’ve gotten a job as a developer it’s time to start taking this serious 🙂 So with my twitter account already existing, and a fresh install of FeedDemon I’m ready to start working my way towards the big guys!

So at this point I’m subscribed to the following feeds:

The people I’m following on Twitter is:

So from now on out I will continously follow and try to keep myself as up to date as possible on php, mysql, general web development and all it’s related topics

November 23, 2010

Tutorial: randomImage() – A “new” way to select random images directly from the directory

Filed under: PHP, Tutorials — Tags: , , , — Ole Aass @ 8:55 pm

So, I stumbled across a very handy php function today called glob().

The glob() function returns an array of filenames or directories matching a specified pattern.
This function returns an array of files/directories, or FALSE on failure.

So I figured this would be great for showing stuff like random ads etc, and had to give it a closer look. The following function is what I used to try it out

 * Select a random image from a directory
 * @param string $path The full directory path to where the images are located
 * @param bool $removePath If this is set to true, only the filename will be returned. (Default: false)
 * @param string $pattern The pattern it will use to filter out what files to grab. (Default: * (will select all filename))
 * @param string $validExtension All valid extensions separated by comma (Default: gif,jpg,png)
function randomImage($path, $removePath = false, $pattern = '*', $validExtensions = 'gif,jpg,png') {

	// Place all image files in an array
	$images = glob($path.$pattern.'.{'.$validExtensions.'}', GLOB_BRACE);
	// Check if the result turned up empty
	if (!$images) {
		return false;
	// Pick a random image from the array
	return ($removePath) ? str_replace($path, '', $images[array_rand($images)]) : $images[array_rand($images)];


print_r(randomImage('images/', false));

Tutorial: getExt() – Get the extension of a file

Filed under: PHP, Tutorials — Tags: , , — Ole Aass @ 6:56 pm

This is probably the shortest function you can make that’s still very usefull

function getExt($filename) {
    return end(explode('.', $filename));

A more advanced version of this function will handle an array of filenames

function getExt($filenames) {

    // Make sure the variable is an array
    if (!is_array($filenames)) {
        $filenames = (array) $filenames;

    // Loop through the array and assign the full filename as
    // index, and the value will be the file extension
    foreach ($filenames as $key => $value) {
        $output[$value] = end(explode('.', $value));

    // Return an array holding the file extensions
    return $output

November 22, 2010

Snippet Manager – A developers best friend

Filed under: Software — Tags: , , — Ole Aass @ 11:07 pm

I’ve been searching for the ultimate snippet manager, but of course that does not exist. Some managers has an online database where you can store your snippets and grab them from anywhere, but they don’t have good syntax highlighting. Others has great syntax highlighting for several often used languages like, C++, PHP, JavaScript, etc, but no shared snippet database meaning it’s on your computer localy and nowhere else.

Tutorial: Handy mysql database object

Filed under: Database, PHP, Tutorials — Tags: , , , , — Ole Aass @ 10:45 pm

I’m tired of typing the same stuff over and over. So I spend alot of time writing reusable code.

No matter if it’s just simple methods or abit more complex objects. Here’s the database object I just wrote. It’s versatile and it really doesnt restrict you to follow any special rules except what objects already restricts you to. You can decide for yourself if you want to complete the query statement or make prepared statement in a valid vsprintf() format.

The following code is examples of usage:

$db = new Class_Database;

$sql = "SELECT * FROM users WHERE username='%s' AND password='%s'";
$inputs = array('username', 'password');

$result = $db->execute($sql, $inputs);
if (!$result)
	return false;
	return true;

or you can use:

$db = new Class_Database;

$username = $db->secureInputs('username');
$password = $db->secureInputs('password');
$sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."'";

$result = $db->execute($sql);
if (!$result)
	return false;
	return true;


Tutorial: emptyStr() the end of long unnecessary if statements

Filed under: PHP, Tutorials — Tags: , , — Ole Aass @ 10:33 pm

This is absolutely not a newsflash for anyone that’s been working a bit with PHP. We always come across situations where we need to make sure strings is or isn’t empty, and what’s more boring than having to write the same stuff for each variable? So i thought, why not make it like the isset() that handles an endless number of arguments? So this is what I came up with:

// Initialize the function
function emptyStr() {

	// Collect all the arguments passed to the method
	// and add them to an array
	$args = funct_get_args();

	// Loop through the arguments
	foreach ($args as $key => $value) {

		// If the argument is not an empty string, return false
		if ($value == "") {
			return true;

	// If none of the arguments are empty strings,
	// return true
	return false;


$var1 = "Hello";
$var2 = "world!";

if (!emptyStr($var1, $var2)) {
	echo $var1.' '.$var2;
} else {
	echo "Failed";

The above code will output: Hello world!

Blog at