Filipino PHP Programmers

October 17th, 2007

Since my primary keyword in my blog is “filipino php programmer”, I would like to write this article that tackles how is the typical life of a Filipino PHP Programmer. I will try to describe bit by bit what are the things that we “filipino PHP programmer” are interested on. This article may be one sided because my basis is just my personal experience in the field of PHP programming. You may agree or disagree with the contents and examples that I will be giving throughout the discussion. You are free to add up your ideas, comments and suggestion after I have submitted this article.

DEVELOPMENT TOOLS

As a programmer in general, in order to develop applications, programs or scripts we need some tools to efficiently code and write down complex algorithmic php programs. As of this date there tons of PHP programming tools available on the net. There are IDEs, Database connectivity client, Code optimizer, code profilers and other tools that being use day to day by Filipino php programmers, may it be at work or at play(writing codes just for fun). But typically what kind of tools that we use? What environment are we working on? I would like to answer these questions by listing some of the tools I know that I am currently using.

1. Development Environment – I know that in order for you to start working on PHP programming you need PHP Engine primarily, the database engine (in my case I use MySQL) and a Web Server (if you wanted to apply your code on the web.) In early days we usually install these engine separately (PHP, MySQL and Apache) in order to start the development. What we try to do is download all 3 engines from their respective websites, read their README and INSTALL files, and follow their instructions there. I still remember those days of spending longs hours configuring Apache to integrate PHP into it, and these lines are still engrave in my mind.

LoadModule php4_module php/sapi/php4apache2.dll

AddType application/x-httpd-php .php

But fortunately today, development environment comes in packages already. Installation packages that comprises of all engines needed to run a full PHP application. Xampp is one of the nice package that I personally use. This cool development package is a one shot installation that comprises already the Apache web server, MySQL Engine, PHP and Perl interpreter. All you need to do is download the installation file or the zip file and run it on you PC, laptop or even server.

2. Editors - like MS Word, Notepad and Wordpad that are document or text editors, PHP programmer need editors to write down their codes. For some PHP programmer I have met and ask, usually have different preferences when it comes to editors. Mostly their choice of editor is their first editor when they started PHP programming. Their reason why sticking to their editor is that they are already adept with it, and changing it will change also their coding preferences and huge adjustment for them. On my personal survey these are the common Editors they are using

Macromedia Dreamweaver – commercial; can run on Windows and Mac

Zend Studio – commercial; can run on Windows, Linux, Unix and Mac; has 30 day trial

Nusphere – commercial; can run on Windows and Linux; has 30 day trial

Vi or Vim – freeware; can run onWindows, Linux and Unix

3. Database applications – database applications are softwares that enable programmer to manipulate database data directly. These database applications enable a PHP programmer to perform DML(Data Manipulation Language) or DDL(Data Definition Language) activity on the Database server. Some of these database applications may be in a web interface like PHP MyAdmin and client side like MySQL CC(not available anymore), MySQL Query Browser, Navicat, EMS, etc.

4. Resources – it is but natural for any programmer to have resources, whether offline or online. Resources are very useful when we are getting syntax of some functions seldomly use, or tags that we are not sure of their structure or even information we can use in our project or task as php programmers. Here are some of the offline resoures that I am using

PHP Help – in chm format

Ebooks – electronic ebooks like, PHP Cookbook, Web Development using PHP & MySQL

Some of the online resources that I usually go whenever I need extra help online are

w3schools – online tutorial on different language and technology which includes PHP, HTML, CSS, etc.

PHP.net - main site of PHP, for online manual

MySQL Reference – mysql reference

DevShed - useful PHP applications and tutorials

5. Other Development Tools/Resources – aside from the tools and resources that I mentioned above. I would like also to list down some important sites that directly or indirectly gives bits of information to my PHP programming life. These are

Digg – researching for latest news on the IT industry.

Sitepoint – gives some useful information on the latest trend on different IT related field like programming, SEO, etc

Mozilla Firefox - the browser itself and the many addons like Bugzilla, Web developers toolbar, Measure It, Colorzilla, and other cool extensions

INTEREST

In this section I would like to describe what are the interest of a typical Filipino PHP Programmer. These interest may or may not be related to programming. Basically these are hobbies, habits, liesure, addictions(non-drug or alcoholic) of some programmers that I’ve known.

Food and Beverages:

Soda – softdrinks in can preferably

Coffee – use to fight drowsiness and boost alertness

Cigarette – study shows that smoking while thinking boost up the ability of the brain to think(well not advised).

Burger – burger machine, burger king

Pizza – pizza hut preferably

Hobbies/Leisures:

RC – remote control cars

Pets – like dogs, fish, etc

Sleeping – no comment

Games – RPG, Online-games, PS2, PSP, Nintendo, Xbox, etc.

to be continued…

Swapping variables without using temporary variable

October 11th, 2007

For example we wanted to swap two variable values given

$x = 10;
$y = 20;

The usual way of exchanging their variables is to use a temporary variable like the one below

$x = 10;
$y = 20;
$z = $x; // $z will be equal to 10 now which will serve as a temporary variable
$x = y; // $x will be equal to 20 now
$y = $z; // $y will be 10 now

Their is another way to do this without using temporary variable is the use of list() function

$x = 10;
$y = 20; 
list($x, $y) = array($y, $x);

You can also do this in multiple variables

$sDog1 = "Boston Terrier";
$sDog2 = "American Bulldog";
$sDog3 = "German Shepperd";
$sDog4 = "Great Dane";
list($sDog1, $sDog2, $sDog3, $sDog4) = array($sDog3, $sDog1, $sDog4, $sDog2); 

Getting a single character in a string

October 9th, 2007

This snippet of code will show how to get individual character from a string in a variable

$sMyName = “Darwin”;

print $sMyName[1]; // will print the letter “a”

How to use heredoc in PHP

October 9th, 2007

Heredoc also known as here-document is a way of specifying string literals or printing them literally without the use of quotes to threat them as literal strings. Heredoc preserves the line breaks and other whitespace (including indentation) in the text.

Heredocs start with <<< and a token or also known as delimiting identifier. The token or delimiting identifier don’t leading or trailing whitespace and followed by semicolon a to end the statement.

Example: We wanted to print this string

The quick brown fox
jumps over the lazy dog.
But what is the name of that dog 
whom the fox jumped over.

Usually we will use the print built in function of php and put line breaks to separate the lines

print "The quick brown fox \n";
print "jumps over the lazy dog. \n";
print "But what is the name of that dog \n"; 
print "whom the fox jumped over \n";

In heredoc we literally print these sequence string without having to print all the lines 1 by 1;

Using heredoc

print <<< DOGS
The quick brown fox
jumps over the lazy dog.
But what is the name of that dog 
whom the fox jumped over.
DOGS; 

Heredocs in HTML

$sAnimal = "cat";
$aZoo = array("elephant","zebra","monkey","lion","bear");
print <<< ZOO
There are different animals in the zoo.
It includes <b>$aZoo[1], $aZoo[3].</b>
There are also <font color="red">$sAnimal</font> here.
ZOO;

My PHP Coding Standard

October 7th, 2007

Before I start writing my own PHP tutorials, I would to set the coding standards I will be following in the course of this tutorial. This aims to standardize all my snippets ( small chunk of code) in all examples I will be giving. I would like to emphasize that this is not a standard to all PHP programmers but just my personal preferences which we all do have.

Comments – - comments are piece of information that programmers usually put to their code to explain what it does. Comments are not actually part of the execution of a program but instead they are ignored by the PHP interpreter. It is a good practice in a programmer to put comments on his code because in the future, comments are the only guide a programmer can follow to understand a big pile of code. Comments may vary depending on what type comment to put.

1. single line comments – for single line commenting I use the double forward slash //

Example:

// this line will print your name
print "My name is Juan dela Cruz";

2. multi-line comment – for multi line I use /* and the closing */

Example:

/*
This is a multi-line comment
and goes all the way
up to this point
*/

Variables

for variables I use the camelize form. Meaning letters in my variable have combination of upper and lower case. But in addition I am affixing a single letter prefix that will determine the datatype of that variable. For example, if I would declare an array variable I would write $aMyArray.

Example:

$aMyArray = array(1,2,3,4); // contains array values
$sYourName = "Conai"; // contains string values
$iLoop = 100; // contains integer values
$oDBConnection = mysql_connect("localhost", "username", "password"); // object
$bIsTrue = false;  // boolean
$mMixedVariable = "test"; // mixed variable, a variable that may vary in datatype

For single usage or single letter variable there is an exemption on my rule.

for ($x=1; $x<count($aMyArray); $x++) {
    <statement here>
}

in the above example $x dont have any prefix on what datatype it is. I have sited this as my exemption.



Constants

as a rule constants should all be in uppercase and words separated by underscore(_)

Example:

define('HOST',  'localhost');
define('USER_NAME', 'root');
define('PASSWORD', '1234567a');



Conditional Statements

if statement

if ($x == 1) {
    <statement here after 4 solid spaces>
}

if – else statement

if ($x == null || $y != false) {
    <statement of if after 4 solid spaces>
} else {
    <statement of else after 4 solid spaces>
}

if -else if – else

if ($x > count($aResults)) {
    <statement of if after 4 solid spaces>
} else if ($x < count($aResults)) {
    <statement of else fif after 4 solid spaces>
} else {
    <statement of else after 4 solid spaces>
}

Loop statement

for loop

for($iCounter=0; $iCounter<10; $iCounter++) {
    <statement of for loop after 4 solid spaces>
}

while

while( !feof($oHandle) ) {
    <statement of while loop after 4 solid spaces>
}

do-while

do {
    <statement after 4 solid spaces>
}  while( $iLoop > 10) ;


Functions - function names are the same as the camelize form of my variables. Function names usually starts with small letters.

Example:

function checkThisVariable($mVariable) {
     if( is_integer($mVariable) ) {
        return "integer";
    } else if ( is_array($mVariable) ) {
        return "array";
    } else {
         return "undetermine";
    }
}

Class - class name are also in camelize form but the first letter is Capitalize to signify that it is a class when placed among other variables.

Example:

class Cabinet {
    var $sDrawer;
    function Cabinet () {
        $this->sDrawer = true;
    }
}

				

Keyword “filipino php programmer”

October 6th, 2007

Wow! is my expression when I found out that my site is #1 on the list when you search the keyword “filipino php programmer” in google.com. At first I cannot believe that my site was first on the list, with the fact that I just written only two topics on my blog. I have come to think that relevance in the keyword really means a lot. Well basically I can say that my site has the relavance since I didn’t write so much about different topic. This has inspired me to write more but following that keyword as my overall topic in my blog.

Setup Smart MMS and GPRS

October 5th, 2007

For Smart Telecom subcriber here is a way to setup your GPRS connection using your handheld.

For MMS
1. Create a message and type in the following

SET MMS <phone model>

For example if I have a nokia 6233 I would type in

SET MMS N6233

and send it to 211

For GPRS

SET GPRS <phone model>

For example if I have a nokia 6233 I would type in

SET GPRS N6233

and sent 211

2. You will then receive a couple of message which are settings for the MMS and GPRS. All you need to do is save them in your connection settings.

3. Usually you will have to wait for less than an hour for this settings to work.

4. To test if the MMS is working, try to send some pictures to yourself via MMS.

5. To test your GPRS for internet connection, usually I do this trick for nokia handheld. I press+hold the “0″ (zero) key and wait for the browser to launch.

6. If still your setup is not working. Try calling *888 for customer support

Mind of the author – blogging

September 30th, 2007

It is not in my nature to be expressive. Its always been so hard for me to express my thoughts may it be in words or in writing. But due to the nature of my job being in the IT industry, I cannot help but to be expose to this new trend of putting your inner thoughts and ideas in writing and have it posted on the web termed as Blogging.

Now is my chance to develop one of my weaknesses in life. The start of bursting emotions, ideas, commentaries, essays and other stuff that may or may not be helpful to other readers that might have accidentally drop to my station. This is the breaking ground of the writer part of me. A new venture into the world of words. Spontaneous appearance of vocabulary words I’ve learn from school days. And most of all the discovery of the real me.

This is the mind of the author.