Of course, you can also specify it yourself. Generally, there are several methods:
( 1 ) <? PHP... ?> // Recommended
( 2 ) <?...?>
( 3 ) < Script Language = "Php" > ... </ Script >
( 4 ) <% ... %>
PHP variable name conventions:
(1) PHP variable names are case sensitive;
(2) The variable name must be dollar sign.$ Start;
(3) The variable name can start with an underscore;
(4) The variable name cannot start with a number..
Single quotes
The simplest way to specify a simple string is to use single quotes (Characters'.
Note: variables in single quotes are not replaced by variable values.
Double quotation marks
If double quotation marks (") are used to enclose strings, PHP understands the escape sequence of more special characters:
The most important aspect of a double quotation mark string is that the variable name is replaced by the variable value.
<? PHP
$ Name = "Jane ";
Print ("Your name is $ name ");
?>
The above script outputs your name is Jane
In PHP, variables can be inserted in strings.
Related Function is_set (): judge whether the variable is set empty (): judge whether the variable is null var_dump (): judge whether the variable type is function: for example, is_int (), determine whether the variable is of the specified type
<? PHP
$ A = "";
$ B = 0;
$ C = 5;
$ D = "hello ";
If (isset ($ ))
Echo "\ $ a defined <br> ";
Else
Echo "\ $ A undefined <br> ";
If (empty ($ B ))
Echo "\ $ B is not empty <br> ";
Else
Echo "\ $ B is empty <br> ";
Echo "\ $ C type is :";
Var_dump ($ C );
Echo "<br> \ $ D :";
Var_dump ($ D );
If (is_numeric ($ C ))
Echo "<br> \ $ C is an integer ";
Else
Echo "<br> \ $ C is not an integer <br> ";
?>
Floats :
<? PHP $ var1 = 3.14?> Floating Point: <? PHP echo $ myfloat = 3.14;?> Round: <? PHP echo round ($ myfloat, 1) ;?> Ceiling: <? PHP echo Ceil ($ myfloat);?> Floor: <? PHP echo floor ($ myfloat);?>
Output result:
Floating Point: 3.14
Round: 3.1
Ceiling: 4
Floor: 3
Booleans :
<? PHP
$ Bool1 = true;
$ Bool2 = false;
?>
$ Bool1: <? PHP echo $ bool1;?> <Br/>
$ Bool2: <? PHP echo $ bool2;?> <Br/>
<Br/>
<? PHP
$ Var1 = 3;
$ Var2 = "cat ";
?>
$ Var1 is set: <? PHP echo isset ($ var1);?> <Br/>
$ Var2 is set: <? PHP echo isset ($ var2);?> <Br/>
$ Var3 is set: <? PHP echo isset ($ var3);?> <Br/>
Output result:
$ Bool1: 1
$ Bool2:
$ Var1 is set: 1
$ Var2 is set: 1
$ Var3 is set:
Typecasting:
<? PHP
$ Var1 = "2 ";
$ Var2 = $ var1 + 3;
Echo $ var2;
?>
<Br/>
<? PHP
Echo GetType ($ var1); echo "<br/> ";
Echo GetType ($ var2); echo "<br/> ";
Settype ($ var2, "string ");
Echo GetType ($ var2); echo "<br/> ";
$ Var3 = (INT) $ var1;
Echo GetType ($ var3); echo "<br/> ";
?>
Output result:
5
String
Integer
String
Integer