Friday, 13 December 2013

Computer Programming: Basic scripting fundamentals in php programming

06:19Friday, 13 December 2013
In computer programming, Script is nothing but it is a set of instructions which work on webpage content to make dynamic changes. PHP provides great environment for script. This code could be embedded or import from outside source in html file. Lets take a simple example, having coded in php programming.

My first PHP program

Writing  the code

  1. Open notepad and write the following code. 
Computer Programming: Basic scripting fundamentals in php programming
  1.  Save this code with extension .php like index.php
  2.  Set the location of your application on server home directory. 

By-default Root directory for different web server are:

Wamp (apache)- C:\wamp\www\mysite
IIS server C:\intetpub\wwwroot\mysite
Xamp (apache) C:\xamp\htdocs\mysite

Here mysite is your home directory where all the php files of your application are saved.

 Running the code:

Open localhost in URL and set the path till your home directory where your PHP file is placed. In above screenshot mysite is home directory of our php application and it is displaying the web page index.php as a default on browser’s windows

Computer Programming: Basic scripting fundamentals in php programming

Analyze the code

Now above output show the result of our php code which we have written in index.php file
  1. The first and last line show the php code syntax which is called php opening and closing tag.
  2. In second line we took a variable $test. Php uses prefix symbol $ to declare a variable. At this instance variable test is empty contains NULL.
  3. In third line we assign some string value This is paragraph to the test variable.
  4. In forth line we are using echo statement which is used to display contents on webpage. This time echo is printing a simple string This is PHP echo code on browser’s window.
  5. In fifth line we are again using echo statement which is printing value of variable $test in new line. This is why because echo statement interprets <br/> html tag when we use it in double quotes. If we wish to print the original string through echo statement then we can use single quotes. The string in single quotes does not interpret and the string will display on webpage is same that it is.
  6. One more thing about this code is we are using description of each line of php-code. By using #, //, /*----*/ syntax. These are prefix which is used to show comments in php file.
Now in last line we are using html comments <! --     --> because it is outside of php code. In this code we used semicolon at the end of line. Which is terminator operators and tells to the compiler about end of statement.
The above code will work fine if use following list of syntax for writing PHP code.

PHP compiler also compiles the code with different syntax like

  • <?php  Php code    ?>
  • <?     ?>   By make enable short_open_tag in php.ini file.
  • <%     %>  By applying asp _tags =on in php.ini file.
*Php .ini is a text file this could be find in Php root folder which contains all the information regarding the Php version which is installed on the machine. We can change php developing environment by updating information on this file like Error handling and logging, Data Handling, Set Resource Limits, File Uploads, Manage Extension, Paths and Directories, Reference etc.
Protected by Copyscape Online Copyright Protection Software


Post a Comment


Toggle Footer