PHP Split string

Source: Internet
Author: User

PHP functions for splitting strings

1,substr

$str 1=substr($str, 5);Echo"Start from the 5th character to the last:".$str 1.";$str 2= substr ($str, 9,4); Echo"Start with the 9th character and take 4 characters:".$str 2.";$STR 3=substr($str--t);Echo"Take the bottom 5 characters:".$STR 3.";$STR 4= substr ($str, -8,4); Echo"Start from the last 8th character and take 4 characters backwards:".$STR 4.";$STR 5=substr($str, -8,-2);Echo"From the last 8th character to the bottom of the 2nd character:".$STR 5.";

2,mb_substr

Mb_substr ($str, $start, $length, $encoding)

$str, the string that needs to be truncated
$start, starting at 0 at the beginning of the truncation
$length, the number of words to intercept
$encoding, page encoding, such as UTF-8,GB2312,GBK

Instance

<?  $str= ' Scripting House: Http://www.jb51.net 'echo mb_substr ($str, 0,4, ' utf-8 '); //  ?>

3,mb_strlen ()

Get Chinese Length: Mb_strlen ()

Mb_strlen ($str, $encoding)

$str, the string to calculate the length of
$encoding, page encoding, such as UTF-8,GB2312,GBK

<?  $str= ' Scripting House: Http://www.jb51.net 'echo mb_strlen ($str, ' utf-8 '); //  ?> results show:

4,strrpos ()

Definition and usage
The Strrpos () function finds the position of the last occurrence of a string in another string.

If successful, returns the position, otherwise false.

Grammar
Strrpos (String,find,start)

Parameter description
string is required. Specifies the string to be searched.
Find required. Specifies the character to find.
Start is optional. Specify where to start the search.

Hints and Notes
Note: The function is case-sensitive. For case-insensitive lookups, use Strripos ().

<? PHP Echo Strrpos ("Hello world!", "Wo"); > Output:6

4,strripos ()

Definition and usage
The Strripos () function finds the position of the last occurrence of a string in another string.
If successful, returns the position, otherwise false.

Grammar
Strrpos (String,find,start)

Parameter description
string is required. Specifies the string to be searched.
Find required. Specifies the character to find.
Start is optional. Specify where to start the search.

Hints and Notes
Note: The function is not case sensitive.

<? PHP Echo Strripos ("Hello world!", "WO"); >

PHP Split string

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.