Click here to return to Code Help Center
HOME    LEARNING CENTER    RESOURCES    NEED A WEB SITE?    NEED WEB HOSTING?    CONTACT US
Training
Learn HTML
Learn XHTML
Learn CSS
Learn JavaScript
Learn ASP
Learn .NET
Learn XML
Learn PHP
Learn Flash
Resources
Guide to SEO
ASCII Reference
HTML Color Names
Free JavaScripts
Free Fonts
Find Clipart
Find Photos
Validators
Validate XHTML
Validate CSS
Link Checker
Link Popularity
 
 
Search Google
 
 
Learn PHP
  1. Introduction
  2. What is PHP?
  3. Install
  4. Syntax
  5. Get more examples

Syntax

You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain HTML. This is because the scripts are executed on the server before the result is sent back to the browser.

Basic PHP Syntax

A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.

Below, we have an example of a simple PHP script which sends the text "Hello World" to the browser:

<html>
<body>

<?php echo "Hello World"; ?>

</body>
</html>

A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document.

Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.

There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".

Variables in PHP

All variables in PHP start with a $ sign symbol. Variables may contain strings, numbers, or arrays.

Below, the PHP script assigns the string "Hello World" to a variable called $txt:

<html>
<body>

<?php
$txt="Hello World";
echo $txt;
?>

</body>
</html>

To concatenate two or more variables together, use the dot (.) operator:

<html>
<body>

<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2 ;
?>

</body>
</html>

The output of the script above will be: "Hello World 1234".

Comments in PHP

In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.

<html>
<body>

<?php//This is a comment/*
This is
a comment
block
*/?>

</body>
</html>
 
< Previous Page  |  Next Page >

Eyepinch web design and development services
 
 
 
Site map
       

 Web Design

A critical element in effectively presenting ideas and content is planning your web site with your targeted audience in mind and creating the intended mood.

 Web Hosting

Eyepinch offers several web hosting packages sure to fit your needs. Speed, quality and service. Let Eyepinch help get your site hosted today!

 Internet Marketing

Let Eyepinch optimize your web site site for search engine placement as we identify specific keywords and phrases pertinent to your business.

 Custom Programming

Eyepinch is well equipped with expert programmers who can help offer you the best solution for your business.