Basic symbols and usage in PHP _php base

Source: Internet
Author: User
Tags string format

Callout symbol:

single-line annotation
/*/multi-line annotation

Use of Quotes

' single quotes, without any sense, without any processing directly brought over;
"" Double quotes, PHP dynamic processing and then output, generally used for variables.

Variable form:

One is true;
The other one is false or false.

Common variable form:

string strings (digital \ Kanji \ etc.)
Integer integers (1, 2, 3, 4, 5, 0,-1,-2, etc.)
Double floating-point number (decimal point)
Array arrays
Object objects

The methods available are GetType ($mix) and Settype ($mix, $typename);

Common symbols

\ "Double Quotes
\ reverse Slash
\ n Line Change
\ r send out
\ t Hop bit (TAB)

Operational symbols

+ addition operation-subtraction operation
* Multiplication Operations/Division operations
% take remainder + + additive
--minus 1. Add strings

Set operation

= Put the value on the right to the left (must be)
+ = Add the right value to the left
-= reduce the value on the right to the left
*= multiply the value on the left to the right.
/= divide the value on the left to the right.
. = Add the right string to the left

Bit-Clerk operation

& and
| Or
^ Mutual exclusion (XOR)
<< left Shift
>> Shift Right
~ Take 1 of the complement

Logical operations

< less than > greater than
<= is less than or equal to >= greater than or equal
!= not equal to && and
|| Or! No

Other operational symbols

$ variable Symbol
Index of & variables (added to the variable before)
@ Do not display error message (added to function)
Methods or properties of the-> object
The element value of the => array
? : Ternary operator

Basic methods

1.PHP conversion string is case-insensitive!

Strtolower (); Turn characters to lowercase
Strtoupper (); Capitalize the character

2.PHP Encrypted string (case-insensitive)

MD5 (); encrypt
SHA1 (); encrypt

3. About Quotes

One, single quotation mark is the original output

Two, double quotes are content interpretation for output

Three, reverse single quotation marks is to execute a command, such as ' pwd '.

Four, "\" role in the translation of characters, such as "\ n" for line-wrapping!

4. Function: Htmlspecialchars ()

This function converts special characters into an HTML string format (&....;). The most commonly used occasions may be to deal with the message version of the customer message.

& (and) Convert to &
"(double quotes) into"
< (less than) turn into <
> (greater than) convert to >

This function converts only the special characters above, and does not convert all to the ASCII conversion specified by HTML.

5. Bulk Output HTML content!

Echo <<< EOT
HTML Output content ... Here the annotation still output!

Print <<<eot
HTML Output content ... Here the annotation still output!

(Note: Internal contains variables with "{variable}")

6. Determine if the file exists and output content

$FileName = "File.TXT";
if (file_exists ($FileName)) {
Echo "<xmp>". File_get_contents ($FileName). " </xmp> ";
Echo "No";

7. Unload variable unset;

Unset ($var);
Unset ($var, $var 1);


Detects whether a variable is an integer;


Detects whether the variable is NULL;


Detects whether a variable is a string


Alias for Is_float ()


Detect whether a variable is set


Detect whether a variable is a Boolean


Detects whether a variable is an array


Detects 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


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

Turn the escaped newline into an HTML <br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.