TUTSCODE PHP 002: THE BASIC SYNTAX OF PHP

PHP HTML

Posted on 2015-07-08 07:47:51


The basic syntax of PHP is the most basic things that we can write a PHP code, maybe it's just a line in the text "Hello wordld".

 A PHP code can be placed in position any files with syntax begins with <? php and ends with?> 

Example:

1
2
3
<? Php
// PHP code
?>

We can also use the <? ?> But want to get it right in the config file php.int. Here I recommend the full syntax <? Php?>.

 A normal external php file containing PHP code, it can contain HTML code. And here I will give a simple example to help people to visualize the shape of a simple php file.

1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
 <html>
 <body>
<h1>Blanka page</h1>
<? Php
 echo "Hello World!";
 ?>
</body>
 </html>

Note: a PHP statement is terminated by a semicolon ";". The pair of characters?> End PHP block it automatically ends the command, we would not necessarily use ";" again. 2. Comments code trong PHP. A code is considered the comment as it is not run as part of the program and so, its effect is allowing someone to read the code easier to understand the writer and may modify it . PHP supports 3 ways to comment in code: For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre>
<!DOCTYPE html>
 <html>
 <body>
<? Php
 // This is the first type of comment
# This is a comment Monday
/*
This type of comment Tuesday
 */
 ?>
</body>
 </html>
<pre>

3. Uppercase, lowercase in PHP In PHP, all function, classs, keywords are not case sensitive distinction. In the following example, the three cases are true:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre>
<!DOCTYPE html>
 <html>
 <body>
<? Php
 ECHO "Hello World!<br>";
 echo "Hello World!<br>";
 EcHo "Hello World!<br>";
 ?>
</body>
 </html>
<pre>

However, all of the variables are to be distinguished from uppercase and lowercase letters. In the following example, only the first statement showing the true value of the variable $ name:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre>
<!DOCTYPE html>
 <html>
 <body>
<? Php
 $name="Blanka";
 echo "My name is " . $name . "<br>";
 echo "My name is " . $NAME . "<br>";
 echo "My name is " . $naME . "<br>";
 ?>
</body>
 </html>
<pre>