Truncation of five kinds of strings

Source: Internet
Author: User

1. Strpos function
Strpos (String,find,start)

Example:
<?php Echo Strpos ("Hello world!", "Wo");
Output 6

2. substr function
SUBSTR (String,start,length)

Where start is the parameter
Positive number-starts at the specified position in the string
Negative number-starts at the specified position from the end of the string
0-Starts at the first character in a string

<?php echo substr ("Hello world!", 6,5); ?>
Output World
3. strstr function
The Strstr () function searches for the first occurrence of a string in another string.
The function returns the remainder of the string (from the matching point). returns false if the searched string is not found.

Strstr ('[email protected]', ' @ ', TRUE); Parameter set True to return the header before the lookup value @, ABC
Strstr (' zhang@jbxue.com ', ' @ '); The default returns the trailing end after the lookup value @, @jbxue. Co

4.STRRCHR ()

STRRCHR (String,char)

The STRRCHR () function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string.

If it fails, it returns false.

strrchr("Hello world!","world");? >

Output:

world!

5.

Similar functions :STRCHR (),

Find the 12th string where it appears, and then intercept to the end!

Truncation of five kinds of strings

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.