Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 2
There are 1 users currently browsing forums.
PHP Articles Read and post PHP tutorials.

Reply
  #1  
Old 01-02-2005
A "Mature" Pre-Teenager!
 
Join Date: Jan 2005
Posts: 101
Rep Power: 6
wizard is on a distinguished road
Php Syntax

Php 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>
Reply With Quote
  #2  
Old 10-06-2005
Banned
 
Join Date: Sep 2005
Location: UK
Age: 25
Posts: 832
Rep Power: 0
bfsog is on a distinguished road
Re: Php Syntax

Well written, however for any noobs you dont have a semi-colon at the end of conditionals and loops.
PHP Code:
$string "im a string so give me a semi colon";
$i// just to know the variable im using
for($i=0$i<=10;$i++) { // no semi colon here
  
echo $i;
// no semi colon here 
Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Tutorial for beginners YoungCoder PHP Articles 19 04-23-2006 02:31 PM
What is PHP? wizard PHP Articles 4 11-27-2005 06:38 AM
PHP Manual [Chris's Version] Chrishasfun PHP Articles 0 01-02-2005 02:22 PM
PHP Installation wizard PHP Articles 0 01-02-2005 02:28 AM
Help ! I need help starting up on Php ! onauc PHP Scripting 5 12-13-2004 12:24 AM