Introduction to how PHP intercepts strings

Source: Internet
Author: User
A very important technique in PHP is to intercept characters of a specified length in a specified string. PHP can use the PHP pre-defined function substr () function to intercept the string to realize, believe that everyone is very clear, then I have those methods!

The code is as follows:

Strpos (String,find,start)

Instance:

The code is as follows:

<?php  Echo strpos ("Hello world!", "Wo");  ? >

Output 6

The code is as follows:

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

The code is as follows:

<?php  Echo substr ("Hello world!", 6,5);  ? >

Output World

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.

The code is as follows:

Strstr (' abc@jb51.net ', ' @ ', TRUE); The parameter sets true to return the header before the lookup value @ abcstrstr (' abc@jb51.net ', ' @ '); The default returns the tail after the lookup value @, @jb51. Net

Summarize:

I believe that everyone through the study of this article, the PHP interception of strings have a certain understanding and understanding, and hope that your work has helped!

Related recommendations:

PHP Intercept string function substr () function instance usage detailed

PHP intercept string (no garbled UTF8)

php intercept string function, PHP custom string interception method

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.