Basic of PHP
Like in ASP, PHP needs special tags to delimit PHP code blocks.
You can use:
If you just want to print a variable:
<? code ?>
<?php code ?>
Most used<script language="php"> code </script>
<% code %>
<?= $variable ?>
Comments:
There are several ways to comment in PHP, you can use C, C++ or Unix shell comment style.
Never nest multiline c-style comments.
<?php echo "Hello, World!<br>"; //this is a c++ style comment /* this is a multiline comment block */ echo "Hello, again.<br>"; #This is a shell-style comment ?>Printing
Again there are several ways to print:
print("This will print");
echo ("This will print");
- Or you can just drop out of php
<?php code ?>This will print to<?php code ?>
Types
PHP supports the following types :
- floating-points numbers
- integers
- strings
- arrays
- objects
The variable type is set by the context of the variable instead of being set explicitly by the programmer.
This can cause some unusual and hard to find bugs. For example the following statement is valid and will result in the number 9 being displayed:
print(3 * "3 little pigs");To help manage variable types, PHP provides the gettype() and settype() functions along with some specific type-checking functions such as is_integer() and is array()
A string is delimited by double quotes("") (with single quotes the following wont work).
variables inside the string will be expanded.
and you can use the backslash to print special characters.
\n New line \r Carriage return \t Horizontal tab \\ backslash \" double quote \$ dollar sign