Some basic functions used by PHP (2)

Source: Internet
Author: User
Some basic functions commonly used by PHP (II) 11. the number of bytes of the variable obtained by The strlen () function $ aaA013strlen ($ aa); the number of bytes obtained is 412. function substr () echosubstr (abcdef, 1 );???? Bcdefechosubstr (abcdef, 1, 3 );?? Bcdechosubstr (some basic functions commonly used by abcd PHP (2)

11. the strlen () function obtains the number of bytes of the variable.
$ Aa = "A013"
Strlen ($ aa); the number of bytes obtained is 4


12. function substr ()
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, 6); // f


The first int parameter represents
Unsigned offset from left to right
Negative number indicates the offset from right to left
The second int parameter represents
Number of characters in the output offset from left to right


Example 1: echo substr ('abcdef', 0, 8 );?? // Abcdef
Indicates that the pointer is located at a if the offset is 0.
Output 8 characters, because there are no 8 characters, then output abcdef.
Example 2: echo substr ('abcdef',-1, 6 );
Indicates that the pointer is located in f if the offset is-1.
Output six characters, because there is only one f, then output f
Example 3: echo substr ('abcdef',-5, 2 );
Indicates that the pointer is in B if the offset is-5.
2 characters are output, which is bc


13. regular expression for Chinese phone numbers:
The current mobile phone number is increased by 150,153,156,158,159,157,188,189.
Therefore, the regular expression is as follows: string s = "^ (13 [0-9] | 15 [0 | 3 | 6 | 7 | 8 | 9] | 18 [8 | 9]) \ d {8} $ ";
^ 1 [3, 5] {1} [0-9] {1} [0-9] {8} $


14. the str_replace () function uses one string to replace other characters in the string. Case sensitive ?? Str_ireplace () performs a case-insensitive search.
Str_replace (find, replace, string, count) parameter description
Find is required. Specifies the value to be searched.
Replace is required. Specifies the value to replace the value in find.
String is required. Specifies the string to be searched.
Count is optional. A variable that counts the number of replicas.


15. The implode () function combines array elements into a string.
Implode (separator, array) parameter description
Optional. Specifies the content to be placed between array elements. The default value is "" (null string ).
Array is required. Array to be combined as a string.


???? The function explode () splits strings into arrays.
Separator is required. Specifies where to split the string.
String is required. The string to be split.
Limit is optional. Specifies the maximum number of returned array elements.

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: info-contact@alibabacloud.com 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.