Archive for the 'Basic Programming' Category

Embedding Comments

Now, to make you a better programmer we all know the value of comments. This allows you to understand the code that you have written defining and given meaning to operations as you build them up. You start with the terminators used by PHP and end with them as well. Single line comments look like this �// comment� and Multi-line ones use the syntax /* comment comment*/. A better example would be the one below:

//comment
/* comment
Comment*/
?>

In the next post we take on the best parts of PHP which would be variables which is essential in all programming languages.

More into the syntax of PHP

As you might have seen, all of the PHP statement ends with �;� which would be somewhat similar to Perl. The valid HTML code that was handed back to the server was :



Who are You?

My name is MacGyver.

More in the coming posts when we dig deeper as we widen our understanding of PHP.

Dissecting/Understanding the first program

The first post had you making a program that was equivalent to the “Hello World” program used for teaching basics of a programming language and here’s how it worked. When the script was requested by opening the web page, Apache intercepted the request and passed it onto PHP which parsed the script looking for the code in between the terminators and then doing the requested operation which was to display the text contained within the echo command. This result was given back to the server then again to the client. The output contained a valid HTML so the browser was able to understand it and execute the requested operation.

Array Combine

This function combines two arrays where the first array is treated as the key and the second array as the contents of the said table. The syntax goes like this : array_combine(array1,array2), wherein the array1 is the table which contains the keys values, and the array2 is the contents. It should be noted that these two tables or array�s should have equal amounts of contents for it would become problematic if there was an error in the combination process. An example of the process is shown below:

$a1=array('a','b','c','d')
$a2=array2("Mouse","Rat","Rodent","Mice")
print_r(array_combine($a1,$a2))
?>

The output of which would give us a single table :

Array ( [a] => Mouse [b] => Rat [c] => Rodent [d] => Mice )

The function combined the two tables giving a single table that combines the keys and the contents. More in-depth discussion on the different array functions which in future posts would be the backbone of applications we will be building.

PHP with Dreamweaver

Dreamweaver 8

Once you open your PHP application such as Dreamweaver, chances are you will be overwhelmed on what you can do with it. In the early stages, you will find yourself being taken aback for the reason that you will see a lot of features such as command lines and scripts that you can use.

Dreamweaver does allow you advanced programming with PHP. However, do remember that you have to start from the bottom. Learning the basics first and slowly integrating them as you go along the way will be the best way to approach it. In short, don’t let your enthusiasm for the software get the best of you. Take it one step at a time.

Fooling Around with PHP

PHP Programming

Although some people may not know it, you can fool around with PHP programming and come up with surprisingly unique yet attractive sites. This includes placing images along with some new scripts which may turn out to be to your advantage in the end as far as presentation is concerned.

So as far as PHP programming to being too technical, think again. You won’t know what you can do until you are upfront with the application itself. Once you do get upfront with it, don’t be surprised if you suddenly find yourself wanting to learn more about this line of programming. It will surely be an interesting journey into programming and development on your end.

PHP’S POPULARITY

smgutmans.jpg

PHP is considered to be one of the most popular server-side scripting systems on the web. And because of PHP’s popularity, a new generation of programmers who are familiar with PHP alone makes it possible to open a “command line interface” for PHP. Along with GUI functions support (Gtk or ncurses support), CLI or “command line interface” is a process of interacting with a computer by providing lines of text commands in written structure either from a keyboard input or from a script. This whole process of command line interface is considered to be a major step for PHP as it stands for its implementation as a genuine programming language.

PHP: server-side scripting

cs.jpg

PHP’s principal focus is server-side scripting which is a web server technology in that involves the process of running a script directly on the web server to create dynamic HTML pages thus fulfilling the user’s request. PHP is originally intended to generate dynamic web pages and its server-side scripting function is the same with other server-side scripting languages that offer dynamic content from a web server to a client, such as ASP.NET system of Microsoft, Sun Microsystems’s JavaServer Pages and mod perl. PHP attracted development of various frameworks (code library made for helping in software development) as well that give building blocks and a design structure to promote rapid application development (RAD).

Variables Used

Variables are used to temporarily keep or store something that you want to save. When the time comes that you will be needing them, recall the variables and they will give you the information that you stored for you to change, delete or edit it.

$message = "Hello Haroon";
echo "PHP Tutorial";
echo $message;
?>

‘Hello Haroon’ is the information that you want to save temporarily, while the message ‘PHP Tutorial’ is displayed.

The output of the program will be: PHP TutorialHello Haroon

In PHP, $ is used to define a variable. PHP, unlike C or Java, is a loose-typing scripting language.

PHP Shopping Cart

Image Source: img141.imageshack.us

Creating a shopping cart with PHP is, quite amazingly, very simple to do. And if you are able to do it correctly, it could spell a big difference between a very efficient system or just a badly written one. The stock’s details should be stored in the database and the only information that is left is the required information, which is the identification of the product that has been added into the cart. The shopping cart must be accessible and there must be ways to access it. One way to do is, the most popular way, having a click button that says ‘Add To Cart’ on that particular page. What it should be able to do next is to be able to update the products in the shopping cart before a new product range shows up.