ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
PHP Tutorial - Index
PHP Tutorial - Introduction to PHP
PHP Tutorial - Your First PHP Script
PHP Tutorial - Operators
PHP Tutorial - Conditional and Looping
PHP Tutorial - Functions
PHP Tutorial - Classes and Objects
PHP Tutorial - Working with Forms
PHP Tutorial - Advanced PHP Topics
PHP Tutorial - Advanced Class Concepts
     

 
Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Makeup Artist Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > PHP Tutorial > Your First PHP Script
 

PHP Tutorial - You First PHP Script

    Page 1 of 2
 

Now that you have installed all the support software for running PHP, you are ready to learn how to do a PHP script.

Writing a PHP script is very simple. No special software is needed, except a text editor like Notepad in which the script is written. You have to run that code on your web browser and you are ready with your first PHP script.

The First Script

A PHP file normally contains HTML tags and some PHP scripting code. A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.

In PHP scripting each line of code must end with a semicolon (;). The semicolon acts as a separator and is used to distinguish between two sets of instructions.

There is a PHP script in the example given below. This script will display the words “Welcome to expertrating!” in the web browser. There are two basic statements to output text on the browser with PHP: echo and print. In the example given below, the echo statement is used to display text.

 

Example

<html>

<head>

<title>Example</title>

</head>

<body>

 

<?php

echo "Welcome to expertrating!";

?>

 

</body>

</html>

 
 

Output

 

How to run your PHP script?

  • Save that script in the web server’s root directory.

  • Open your web browser and type “//localhost/directory name/filename.php” and then press enter.

  • By doing this the script will run in your browser.

Variables

Different languages have different ways of defining a variable. Similarly, in PHP variables are defined in a unique manner. All variables in PHP start with a $ sign symbol. Variables may contain strings, numbers, or arrays.

If you want to assign a string to a variable, then you have to put that string into quotes “ “ like: “Hello! How are you?”. If you want to assign a number to a variable then there is no need to include it into the quotes.

The code to display a variable on the screen is same as the code to display normal text. The variables are also displayed with the echo command e.g. echo $abc.

This is an example in which a string is assigned to a variable, which is further displayed on the web browser.

 

Example

<html>

<head>

<title>Example</title>

</head>

<body>

 

<?php

$txt ="Hello and Welcome to expertrating.";

echo $txt;

?>

 

</body>

</html>

 

 

     

 

 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2015. All Rights Reserved.