SoFunction
Updated on 2025-04-09

Basic symbols and usage methods in PHP

Annotation symbol:

// Single line annotation
/* */ Multi-line annotation

Use of quotes

' ' Single quotes have no meaning and are taken directly without any treatment;
" "Double quotes, php dynamically processed and then output, which is generally used for variables.

Variable form:

One is True, that is, true;
The other is False, that is, false

Common variable patterns:

string string (number\Chinese characters\etc)
integer integer (1, 2, 3, 4, 5, 0, -1, -2, etc.)
double floating point (decimal point)
array array
object object

The methods that can be used are gettype($mix) and settype($mix,$typename);

Common symbols

\" Double quotes
\\ Backslash
\n Line break
\r Send out
\t Jump position (TAB)

Operator symbols

+ Addition - Subtraction
* Multiplication / division
% Take the remainder ++ Accumulate
-- Cumulative 1. Add strings

Setting operation

= Substitute the right value into the left (must know)
+= Add the right value to the left
-= Subtract the value on the right to the left
*= Multiply the left value by the right
/= Divide the left value by the right
.= Add the string on the right to the left

Staff operation

& and
| or
^ Mutual Exclusion (xor)
<< Shift to the left
>> Shift to the right
~ Take the complement of 1

Logical operations

< Less than > Greater than
<= Less than or equal >= Greater than or equal
!= does not equal && and
|| Or ! No

Other operator symbols

$ variable symbol
& variable indicators (added before variables)
@ No error message is displayed (added before function)
-> Object method or property
=> Element values ​​of array
? : Triple operator

Basic Methods

Convert string to upper and lower case!

strtolower(); convert characters to lowercase
strtoupper(); convert characters to uppercase

Encrypted strings (both upper and lower case)

md5(); Encryption
sha1(); Encryption

3. About Quotes

1. Single quotes are output as is

2. Double quotes are the content interpretation for output

3. Anti-single quotes are to execute a command, such as `pwd`.

4. "\" acts on the translated characters, such as "\n" is a newline!

4. Function: htmlspecialchars()

This function converts special characters into HTML string format ( &...; ). The most commonly used occasion may be to process the message version of customer messages.

& (and) convert to &
" (Double Quotes) to "
< (less than) to <
> (greater than) to >

This function only converts the special characters above and will not all convert into the ASCII conversion specified in HTML.

5. Batch output HTML content!

echo <<< EOT
HTML output content. . . //The comments here are still output!
EOT;

Print <<<EOT
HTML output content. . . //The comments here are still output!
EOT;

(Note: Use "{variable}" to include internal variables)

6. Determine whether the file exists and output the content

<?php
$FileName="";
if (File_Exists($FileName)){
Echo "<xmp>".File_Get_Contents($FileName)."</xmp>";
}else
{
Echo"no";
}
?>

7. Uninstall the variable unset;

unset($var);
unset($var,$var1);

8.is_int;

Detect whether a variable is an integer;

9.is_null;

Detect whether the variable is NULL;

10.is_string

Detect whether a variable is a string

11.is_real;

is_float() alias

Detect whether the variable is set

13.is_bool

Detect whether the variable is boolean

14.is_array

Detect whether a variable is an array

15.is_object

Detect whether a variable is an object

.

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

17.Nb2br

echo nl2br("foo isn't\n bar");

Turn escaped line breaks into HTML<BR />