Monday, July 19, 2010

PHP tutorial Part2

Posted by Syarif | Monday, July 19, 2010 | Category: |

Syntax of PHP

When you start to write PHP, you must type the ‘box’ so that code of PHP can be read by the webserver.
Example:

<? . . . . ?>


Write word in php
If you want to start write in PHP (not in HTML mode), you should put “echo” in order to make word visible.
For example:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<? echo ("this is PHP code")?>
<body>
</body>
</html>



Semicolon (;)
You will use semicolon to separate the code of PHP.
For example:

<? Echo (“Hi there!”);
Echo (“Hi there!”);
Echo (“Hi there!”);
Echo (“Hi there!”);

Echo (“Hi there!”);
?>



Make variable for PHP
In PHP, you must always remember that name of variable must be declare with ‘$’.
For example :

<?
$variable = “Hi there!”;
$variable2 = 1;
$variable3 = 3;
?>



Show the value of Variable with Echo
If you want to declare your variable value, you can use echo for this case.
For example:

<?
$variable = 12;
Echo $variable;
?>



Give comment in PHP
In PHP, if you want give some comment in order to help you and others to know what the means of your code, you must put “//” for one row and /* . . . */ for more than one row. The comment will not be printed in your webpage. So, don’t worry to put the comments to help yourself.
For example:

<?
Echo (“this is my first PHP . . . .”); //and this is the comment
?>



or


<?
Echo (“this is my first PHP”);
/* don’t worry . . .
It will not be printed in your webpage
*/
?>

Currently have 0 comments:


Leave a Reply