Technology Programming

PHP Training for Beginners

    PHP Script Syntax

    • A basic functional PHP script looks something like this:

      <html>

      <head>

      <title>

      My First PHP Script

      </title>

      </head>

      <?php

      Echo date ('J F Y');

      ?>

      </html>

      The script above contains both HTML and PHP code. The code between "<?php" and "?>" is PHP code that is first passed through the web server before being displayed onto the web browser.

    The "echo" Command

    • The "echo" command is used to send output to the browser. The example below prints the statements under the quotes the same way a normal HTML file would. We use PHP to display the text as shown:

      <?php

      echo "This is My First PHP Script."

      <?

    PHP Variables

    • Variables in PHP are used to store and retrieve data and values by declaring them using the dollar sign as shown below:

      $Name = David;

      In PHP, variables can be used even before they are declared. A variable can be declared and used anywhere in PHP code.

    Conditional Statements

    • These are statements used to evaluate and execute conditional statements using the "if" statement. The example below shows how the "if" statement can be used to check a certain criteria and output the result if the case is true:

      $Name= David;

      If ($Number>5) {

      Echo "$Name is greater than 5";

      }

      The above echo statement will only display when the number is greater than 5. This statement can be used to evaluate both number and word values.

    Loop Statements

    • Loop statements are used to repeat code blocks when a certain condition is met. The example below shows how to use the "while" loop to display the square of numbers from 1 to 5:

      $count=1;

      While ($count <=50 {

      4square = $count * $count;

      echo "$count squared is $square ";

      $count++;

      }

      Loops can also be performed using the "do" and "for" loop statements for varying conditions that meet or fail to meet certain criteria.

    PHP Functions

    • Functions are used to simplify code use and maintenance. A sample code looks like this:

      Function tax($amount) {

      $total = $amount 8 2;

      Return $total;

      The code above can be called each time for each product.

SHARE
RELATED POSTS on "Technology"
WordPress - How to Set up a New Theme to WordPress 3.
WordPress - How to Set up a New Theme to WordPress 3.
Solution of Creative Web Design
Solution of Creative Web Design
The three disciplines of User Experience
The three disciplines of User Experience
Web Design Sheffield Options For Professional Enterprises
Web Design Sheffield Options For Professional Enterprises
Do you have what it takes?
Do you have what it takes?
Segway Cost
Segway Cost
Microsoft Access 2010: What's Coming with Office 2010?
Microsoft Access 2010: What's Coming with Office 2010?
Companies of Web Development in Ireland Provide Designs that Work
Companies of Web Development in Ireland Provide Designs that Work
Penguin Update to Put Red-Flags on Negative SEO
Penguin Update to Put Red-Flags on Negative SEO
Innovative web 2 design templates can make your business famous quickly
Innovative web 2 design templates can make your business famous quickly
Building A Search Engine Friendly Website
Building A Search Engine Friendly Website
Exceptional Advice To Build Up Your Internet Marketing
Exceptional Advice To Build Up Your Internet Marketing
The Benefits of Selecting The Right Hosting Company
The Benefits of Selecting The Right Hosting Company
Is There a Methodology for Making Successful Logos
Is There a Methodology for Making Successful Logos
Benefits of Ruby On Rails Development
Benefits of Ruby On Rails Development
The Power of Colour and Shapes in Your Infant's Life.
The Power of Colour and Shapes in Your Infant's Life.
Advantages of Hiring PSD To HTML Service Providers
Advantages of Hiring PSD To HTML Service Providers
How to Make Responsive Web Design Attractive?
How to Make Responsive Web Design Attractive?
Converting PSD to Responsive HTML
Converting PSD to Responsive HTML
Just a few realy really hints and tips when it comes to website design but look for.
Just a few realy really hints and tips when it comes to website design but look for.

Leave Your Reply

*