Things to know about PHP
Here are quick note and little attention that you should know before writing project code in PHP.
Basic PHP sysntax:
A PHP script starts with <?php and ends with ?>:
Basic PHP sysntax:
A PHP script starts with <?php and ends with ?>:
<?php
// Your PHP code goes here
?>
The default file extension for PHP files is ".php".
Note: All statements must end in a semicolon ( ; )! Otherwise, errors will be
generated. If the error doesn't make sense, you probably are missing a
semicolon somewhere!
Comments in PHP
A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is looking at the code.
Example on PHP comments:
<!DOCTYPE html>
<html>
<body>
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines in your project
*/
// You can also use comments to leave out some parts of a code line$x = 15 /* + 15 */ + 15;
echo $x;
?>
</body>
</html>
<html>
<body>
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines in your project
*/
// You can also use comments to leave out some parts of a code line$x = 15 /* + 15 */ + 15;
echo $x;
?>
</body>
</html>
The output of the above code will be 30. (x = 15+15)
PHP case sensitive
In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive.
In the example below, all three echo statements below are legal (and equal):
<!DOCTYPE html>
<html>
<body>
<?php
ECHO "Hello PHP!<br>";
echo "Hello PHP!<br>";
EcHo "Hello PHP!<br>";
?>
</body>
</html>
<html>
<body>
<?php
ECHO "Hello PHP!<br>";
echo "Hello PHP!<br>";
EcHo "Hello PHP!<br>";
?>
</body>
</html>
Formatting Characters in PHP
\n– New line
\r– Carriage return
\t– Tab
\b– Backspace
Comments
Post a Comment