Basic symbols and usage in PHP
- 2020-03-31 20:33:44
- OfStack
Annotations:
// single line comments
Multi-line comment
Use of quotation marks
"Single quotation marks, no meaning whatsoever, take it without any processing;
"" double quotes, PHP dynamically handles and then outputs, typically used for variables.
Variable form:
One is True;
The other is False
Common variable morphology:
String (number, Chinese character, etc.)
Integer (1, 2, 3, 4, 5, 0, -1, -2, etc.)
(decimal point)
Array an array
object
Gettype ($mix) and settype($mix,$typename) can be used.
Commonly used symbols
\ "double quotation marks
\ \ the backslash
\ n line
\ r
\ t jump (TAB)
Sign of operation
+ addition operation - subtraction operation
* multiplication/division
% remainder ++ add
Add up the strings
Set the operation
= substitute the value on the right into the value on the left.
+= add the right-hand side to the left-hand side
Minus PI equals minus the right-hand side to the left-hand side
*= multiply the left-hand side by the right-hand side
/= divide the left-hand side by the right-hand side
.= add the right string to the left
A member of the operation
& and
| or
^ the mutex (xor)
< < Shift to the left
> > Shift to the right
Take the complement of 1
Logical operations
< Less than > Is greater than
< = less than or equal to > Is greater than or equal to
! = is not equal to ampersand and
| | or! Don't
Other operational symbols
$variable sign
Indicator of a variable (added before the variable)
@ does not display error message (added before function)
- > Object's methods or properties
= > The element values of the array
? : ternary operator
Basic method
1.PHP converts strings to case!
The strtolower (); Convert characters to lowercase
The strtoupper (); Convert characters to uppercase
2.PHP encrypted string (case or case)
The md5 (); encryption
Sha1 (); encryption
3. About quotes
One, the single quote is the original output
Two, the double quotation mark is the content explanation carries on the output
Anti-single quotes execute a command such as' PWD '.
Four, "\" on the translation character, such as "\n" for line break!
4. The function: htmlspecialchars ()
This function converts special characters to HTML string format (&... ; ). One of the most common situations is probably the message board for customer messages.
Ampersand becomes ampersand
"(double quotation marks) to"
< (less than) into <
> (greater than) into >
This function converts only the above special characters, not all of them to the ASCII conversion specified in HTML.
5. Batch output HTML content!
Echo < < < EOT
HTML output... // comments are still output here!
EOT;
Print < < < EOT
HTML output... // comments are still output here!
EOT;
(note: "{variable}" is used to contain variables internally.)
6. Determine whether the file exists and output the contents
< ? PHP
$FileName = "File. TXT";
If (File_Exists ($FileName)) {
Echo "< Xmp>" File_Get_Contents ($FileName). "< / xmp>" ;
} the else
{
Echo "no";
}
? >
7. Uninstall variable unset;
The unset ($var);
The unset ($var, $var1);
8. Is_int;
Test whether the variable is an integer;
9. Is_null;
Detect whether the variable is NULL;
10. Is_string
Detects if the variable is a string
11. Is_real;
Is_float (alias)
12. Isset
Detects whether a variable is set
13. Is_bool
Test whether the variable is Boolean
14. Is_array
Checks whether the variable is an array
15. Is_object
Detects whether a variable is an object
16. The SubStr.
SUBSTR (String, Start, SelectNum)
Echo substr (" abcdef ", 1); / / bcdef
Echo substr (' abcdef, 1, 3); / / BCD
Echo substr (' abcdef '0, 4); / / the abcd
Echo substr (' abcdef '0, 8). / / abcdef
Echo substr (' abcdef, 1, 1); / / f
17. Nb2br
Echo nl2br (" foo isn 't \ n bar ");
Change escaped newlines to HTML < BR / >