Get Your Tools

November 25th, 2008

Image Source: moonsdesigns.com

Before you can start with your PHP programming, you will surely need some few things handy. To be able to create a PHP page, you will need to have a simple text editor. A text editor is a small program that enables you to edit files in plain text. Usually these files are those that have extensions like .php, .html, .cgi and many others. This is an essential tool because your file , when saved should not be formatted, it should be saved in plain text. Notepad is a simple text editor that works only on Windows and Text Edit is another plain text editor that solely works on Mac OS. Next thing you should have is an FTP. This will be used to transfer files to and fro to a remote server. When you already got them, you can now start creating your PHP pages.

フローコントロールと反復

November 17th, 2008


写真提供:theopensourcery.com

フローコントロールと反復はほとんどのプログラミング言語で使用される特徴です。これら無しではプログラムは線形です。フローコントロールは文字通りです。フローコントロールはあなたにコード実行の順番、実行回数、実行の有無などを管理させます。フローコントロールは主に三つのカテゴリーに識別されます。

  • 条件的 – 条件により、選択されたコードが実行されるかどうかを指定します。
  • 反復 - ルーピングとしても知られ、コードが何回実行されるか指定します。
  • 機能 - スクリプト内でブロック化されたコードの名前付けを許可します。 コードをスクリプト内の複数場所で複数回実行します。

Write secured PHP

October 6th, 2008

Image Source:sitepointstatic.com

PHP programming was written to be an easy language to program. Completely opposite to being very security oriented. It was so until the 4.1 version. Undeniably, Php has grown to be popular in the short term. But it also created many, many, very badly written scripts. And it gave a very big number of programmers a mindset which is not inclined to the security aspect of programming. Maybe, the main reason behind it, is the automation of conversion by PHP of inputted data to script variables using or enabling though php.ini setting register globals. In the 4.1 version of PHP, this type of behavior was left enabled but was not recommended to be used. With PHP 4.2, this type of behaviour was disabled by default. It broke thousands and thousands of scripts worldwide. This dilemma led to forcing the coders to write more secure codes. They made scripts break. This was opposed stongly before but somehow they saw that the move was a smart one.

Flow Control and Iteration

September 29th, 2008


Image Source:theopensourcery.com

Flow control and iteration are two useful features in most programming languages. Without them, programs would be linear.Flow control means exactly what it sounds like. Control the flow. When using flow control, you are regulating the order in which the code is executed, the number of times it is to be executed or if it is executed at all. Flow control can be classified into three primary categories.

  • Conditionals – specifies whether or not to run a selected piece of code based on some conditions.
  • Iteration – also known as looping, it specifies that a piece of code be run a number of times.
  • Functions – allows you to create named blocks of code to be called by name in the script. This runs a piece of code multiple times from multiple places in the script.

Looping Statements Doesn’t loop?

August 10th, 2008


Image Source: www.pragprog.com
Did you know that looping statements doesn’t loop the whole if-else statement if you put an if-else statement in the looping statement? That’s right. Looping statements only goes through the if-else statements once. Once the looping statement activates the statements inside the if-else statement, the looping statement will only loop the statement inside the if-else statement. That is why it is not recommendable to use if-else statement inside a looping statement, such as do-while statements, while statements, and for statements. The only thing I recommend for you to use a switch statement. Looping statements reads the whole switch statement, possibly because switch statements requires a specific value for a condition. I don’t really know, but it works. Don’t worry. Switch statement also has a “Default” statement inside it that works just like the “else” statement in the if-else statement. The only disadvantage is that you won’t be able to set comparisons like greater than (») or less than («).

Arrays

July 1st, 2008

Arrays are what tables are to C-based programming languages and what databases are for SQL-based languages. Arrays or tables as they are sometimes called can be used to store the contents of several variables and to create one, you use the following syntax:

Array(key=>value)

The array in the syntax refers to the name of the array being created, the key is the index which is set automatically to a numeric character or string if none is specified. Value is the assigned value or content of the said array which can be seen easily in the following array creation example:

$b=array('z'=>‘Comedy”,’y'=>”Horror”,’x;’=>”Action”);
print_r($b);
?>

This piece of code would produce an output of :

Array ([0] => Comedy [1] => Horror [2] => Action)

More on array functions in the next posts.

Getting Started with PHP Programming

June 1st, 2008

The first step to get us on our way to programming in PHP would be to set up an ideal development environment. You need a Web Server software like Apache (which would be what we are going to use) which is only one of many out there. Most of these web servers are open-source meaning that they are free. Now, being free doesn�t mean that they are not up to standards for there are standards that are set by independent groups that are comprised of the many developers who together formulate or give a loosely defined set of standards for others to follow. Apache has versions for Linux but there are also for the Windows, Unix and Mac OS. The installer can be downloaded along with the detailed manual from PHP.net

Further shortening of your code (Part 2)

May 17th, 2008

As stated in the previous entry, shortening or simplifying your source code makes it easier and better when you need to find bugs and a good example of this would be :

Example :
if ($Mickey == true) echo ‘Welcome to the Mickey Mouse Club House’;
elseif ($MainCharacter == false) echo ‘Hi Barney!’;

Making things a bit simpler, say by taking away the ‘==’ and ‘!=’ gives you;

if ($Mickey) echo ‘Welcome to the Mickey Mouse Club House.’;
elseif (!$MainCharacter) echo ‘Hi Barney!’;

Simplifying code should be the aim of each and every programmer (who’s head aches when you get some bugs you got to fix) so you get to code less and better than the other guy. Remember, we’re all on the same plane using the same free language so we should be helping others for the better.

Further shortening of your code (Part 1)

May 13th, 2008

Many people are using PHP for development and most have truly mastered the art of programming the easy way round. Sadly, many older web sites that used these older styles of programming are not only long but reminiscent of reading something similar to alien writing that is long and incomprehensible to the layman. But good for all of us, there are some people out there who are willing to share their learned ways to those who are just beginning to master the strengths and powers of PHP. The traditional PHP way of checking for Boolean expressions was long and filled with those double equal signs (==)and others that were akin to some other mathematically adept languages but there are simpler ways of doing things as there always is with any language. In the next post we would give and example of the concept.

Control Structures

May 9th, 2008

There used to be an old saying in PHP that a control structure needs a single constant to locate it and a set of brackets to clear it all up. Well, that might all be true but using too many of these curly brackets when it isn’t needed at all doesn’t help you any and it even makes your code a tad bit harder to understand. Let’s show this with the following example:

if ($superman == ‘alien’) {
$strength — ;
}

Saying that, it would be simpler to code it in this simpler more readable manner:

if ($superman == ‘alien’) $strength — ;

The fewer brackets that muddle up the code the better for it makes it all the readable thus easier to understand and fix in case something goes wrong.