Thursday, January 21, 2010

An Introduction to Php 1001

Your computer should have at least php5 and apache 2.x webserver installed and running before you can try out the examples or write some php code.  Mysql database server will be need to be installed for trying out php connections to Mysql. See my 1st article for how to ideas.

All php scripts are saved with a .php extension e.g index.php.

For writing php scripts any text editor will do, however text editors with line numbering and syntax highlighting are the best. There are good open source and paid text editing software you can use e.g leaf text editor and notepad +. A good commercial text editing software is Rapid HTML. You can google for these to find out more.

All php scripts should be saved in your webroot folder e.g  c:/myfolder/www/myfile.php

Note: I test run all examples before posting them, if you find typo or execution errors, etc, your feedback would be welcome.

To execute above script, you would type the following in your web browser:
http://localhost/myfile.php  Note: all script file names are case sensitive.

Some important points to remember:

All php scripts start with <?php
And end with ?>
Semi colons are used to terminate end of line for some code.
Comments inside php use /*   */  for long comments ,   #  for  bold comments ,  // for single line comments.

Example:

<?Php

//This is one line comment

/* this is multi line comment
and more multi line comment */
##################
#My boxed comment#
##################
echo “hello”;
?>


Save above example as myfile.php or similar and run it in your web browser. It should display “Hello” on your screen.

0 comments:

Newer Post Older Post Home