PHP find string Common functions Introduction _php tutorial

Source: Internet
Author: User
The first occurrence of a strstr-lookup string

String Strstr (String $haystack, mixed $needle [, bool $before _needle = false])
Note 1: $haystack is a string of characters, $needle is the string being looked up. The function is case-sensitive.
Note 2: The return value starts from needle to the end.
Note 3: For $needle, if it is not a string, it is used as the ordinal of the character as an integer.
Note 4:before_needle If true, the previous thing is returned.
Copy CodeThe code is as follows:
$email = ' yuxiaoxiao@example.com ';
$domain = Strstr ($email, ' @ ');
Echo $domain; Print @example. com
$user = Strstr ($email, ' @ ', true); From PHP 5.3.0 onwards
Echo $user; Print Yuxiaoxiao
?>


Second, stristr strstr case-insensitive version
Strpos-Find where the string first appears

int Strpos (string $haystack, mixed $needle [, int $offset = 0])
Note 1: The optional offset parameter can be used to specify which character in the haystack to start the lookup. The number position returned is relative to the starting position of the haystack.
Iv. substr-Returns a substring of a string

String substr (string $string, int $start [, int $length])
$rest = substr ("abcdef",-1); Return "F"

Note 1: If Start is non-negative, the returned string starts at the start position of string and is calculated from 0. For example, in the string "ABCdef", the character at position 0 is "a", the string for position 2 is "C", and so on.

Note 2: If start is a negative number, the returned string starts at the end of the string, starting at the start of the first character.

Note 3: Returns FALSE if the length of the string is less than or equal to start.

Length

Note 4: If a positive length is provided, the returned string will contain a maximum of length characters (depending on the length of the string) starting at start.

Note 5: If the length of a negative number is provided, then many of the characters at the end of the string will be omitted (if start is negative, count from the tail of the string). If start is not in this text, an empty string is returned.

Note 6: If a length of value 0,false or NULL is provided, an empty string is returned.

Note 7: If length is not provided, the returned substring starts at the start position until the end of the string.
Copy CodeThe code is as follows:
$rest = substr ("abcdef", 0,-1); Back to "ABCDE"
$rest = substr ("ABCdef", 2,-1); Back to "CDE"
$rest = substr ("ABCdef", 4,-4); Return ""
$rest = substr ("ABCdef",-3,-1); Return to "de"
?>

V. STRRCHR-Find the last occurrence of a specified character in a string

String STRRCHR (String $haystack, mixed $needle)

The function returns a portion of the haystack string, starting at the last occurrence of needle, until the end of haystack.

Vi. Strripos-Calculates the position of the last occurrence of the specified string in the target string (case insensitive)
Vii. Stripos-Find where the string first appears (not case-sensitive)
Viii. Strrpos-Calculates the position of the last occurrence of the specified string in the target string

http://www.bkjia.com/PHPjc/325605.html www.bkjia.com true http://www.bkjia.com/PHPjc/325605.html techarticle the first occurrence of the strstr-lookup string Strstr string (string $haystack, mixed $needle [, bool $before _needle = false]) Note 1: $haystack Is the party string, $needle is checked ...

  • Related Article

    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.