PHP common special operation symbols and function summary of php beginners must see
- 2020-05-27 04:37:00
- OfStack
Annotated symbols:
// one-line notes
Multi-line comment
Use of quotation marks
"Single quote, simple string, brought in without any processing;
"" double quotes,php dynamic processing and then output,1 generally used to handle the $variable.
Boolean variable:
One is true which is true;
The other is false, which is fake
Common variables:
string string (Numbers, Chinese characters, etc.)
integer integers (1, 2, 3, 4, 5, 0, -1, -2, etc.)
double floating point number
array array
object object
The available methods are gettype($mix) and settype($mix,$typename);
Common symbol escape:
\ "double quotation marks
\ \ the backslash
\ n newline
\ r back to the beginning of a line
\t horizontal tabulation
Operation symbol:
Plus plus minus minus
* multiplication/division
Take the remainder of % ++ add 1
Concatenate two strings
Assignment operation:
= substitute the value on the right into the value on the left
+= add the right-hand side to the left-hand side
-= subtract the right-hand side from 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
Operation:
&
Bitwise and
| or by location
^ by bit or (xor)
<
<
We're going to move 1 bit to the left
>
>
I'm going to move 1 bit to the right
~ take a complement
Logical operation:
<
Less than
>
Is greater than
<
Is less than or equal to
>
Is greater than or equal to
! = is not equal to
&
&
with
| | or! non
Other operation symbols
$variable symbol
&
Variable alias
@ does not display error message (added before function)
-
>
Object's methods or properties
=
>
The element values of the array
? : 3 meta operator
Common basic methods:
1.PHP converts strings to case!
strtolower (); Convert characters to lowercase
strtoupper (); Convert characters to uppercase
2.PHP encrypted string
Non-reducible:
md5();
sha1();
Can restore:
base64_encode();
base64_decode();
3. About quotation marks
1. Single quotes are output as is
2. Double quotation marks are content interpretation for output
3. Anti-single quotes (small quotes) are the execution of a system command, such as' dir '. Often used in table names, field names above.
4. "\" ACTS on the translated characters, such as "\n" for line feed.
4. Functions :htmlspecialchars() and htmlentities()
This function converts a special character to the string format of HTML (
&
. ; ). One of the most common situations is probably the message board for customer messages.
&
(and) turn into
&
amp;
"(double quotation marks)
&
quot;
<
PI is less than PI
&
lt;
>
(greater than) into
&
gt;
(blank) into
&
nbsp;
5. Batch output HTML content!
echo
<
<
<
EOT
HTML output content... // comments are still output here!
EOT;
print
<
<
<
EOT
HTML output content... // comments are still output here!
EOT;
(note: "{variable}" is used for internal containing variables.)
6. Determine whether the file exists and output the content file_exists ()
<
?php
$FileName="File.TXT";
if (file_exists($FileName)){
echo "
<
pre
>
".file_get_contents($FileName)."
<
/pre
>
";
}else
{
echo"no";
}
?
>
7. Delete variables to free memory unset();
unset($var);
unset($var,$var1);
8.is_numeric;
Test whether the variable is a number;
9.is_int;
Test whether the variable is an integer;
10.is_null;
Test whether the variable is NULL;
11.is_string
Detects whether the variable is a string
12.is_real;
is_float (alias)
13.isset
Detects whether a variable is defined
14.is_bool
Test whether the variable is Boolean
15.is_array
Detects whether the variable is an array
16.is_object
Detects whether a variable is an object
The 17.substr() function returns part 1 of the string.
substr (String,Start,SelectNum)
echo substr('abcdef', 1); // bcdef
echo substr('abcdef', 1, 3); // bcd
echo substr('abcdef', 0, 4); // abcd
echo substr('abcdef', 0, 8); // abcdef
echo substr('abcdef', -1, 1); // f
18.nb2br() changes the escaped newline to html
<
br /
>
echo nl2br("foo isn't\n bar");