Embed page mode
JS Embedding mode:<script></script>
Php Embedding method: <?php
?> (Common)
Output syntax
JavaScript output
1.alert ("Content of the warning")
2.prompt ("Content of the hint")
3.document.write () (Page output content)
PHP output
1.echo (Common)//can output multiple strings at the same time Eg:echo $a, "hello";
2.print//can only output one string eg:print $a;
3.print_r ();//can print an array
4.var_dump ();//the content, type and length of the variable can be output
Data type
JS data type
Integer (integer) int
Single Precision fractional float
Double-precision Decimal double
Fractional decimal
boolean bool (can only save two states)
Date Time Type datetime
Character char (infrequently used) strong
Strings string (infrequently used) strong
PHP Data type
BOOL Boolean type (stores two states)
int integral type
Float (double) floating point type
Char character
String strings
Defining variables
JS definition variable: var a = 10;
(Note: 1. If you define an integer or decimal variable, the value after the equal sign is written directly
2. If you define a string variable, the value after the equals sign needs double or single quotation marks.
PHP definition variables: $a = 5; $a = "Hello"; $a = <<<a defined string contents//can also put HTML code A;
(Note: 1. If you define an integer or decimal variable, the value after the equal sign is written directly
2. If you define a string variable, the value after the equals sign needs double or single quotation marks.
string concatenation
JS string concatenation: "+"; eg: "Hello" + "world"
string concatenation in PHP: "."; eg: "Hello". " World
PHP-specific variable characteristics
Escape character: Typically used in strings to output special content
\ "Output double quotes \ t tab \ n line break
eg: $s = "wo\" Rld "; Escape quoted $s = "wo\trld"; escape tab $s = "wo\nrld"; Escaping line breaks
$a = "Hello";
Parsing variables
$b = "hello{$a}"; Output Hello, hello
Type conversions
Type conversion in JS
1. Convert to Integer: parseint ();
2. Convert to Decimal: parsefloat ();
3. Determine whether it is a valid number type: IsNaN ();
Type conversion in PHP
1. $a = (Int) $a; Forced conversion variable A is an integer
2. $b = Settype ($b, "string"); Forced conversion variable A is a string
Common functions of variables in PHP
$s = 5;
1.var_dump (Empty ($s)); Empty ($s) determines whether the variable s is empty, can be 0, can be an empty string, or it can be undefined
2.unset ($s); Delete variable S
3.var_dump (Isset ($s)); Isset ($s) determine if the variable s is defined
Special usage in PHP
1. Variable take address
$a = "Hello";
$b = & $a; & Represents the address of the variable
Echo ($b); The result of the output is Hello
2. Variable variable
$s = "HI";
$hi = "Hello";
echo $ $s; The output is hello.
The difference between PHP basics and JS Operations