Determines whether a character is in a string in PHP

Source: Internet
Author: User

Tag: Ring POS class starts start return function Art font

    1. Strpos () -finds the position of the first occurrence of a string in another string (case-sensitive)
    2. Stripos () -finds the position of the first occurrence of a string in another string (case insensitive)
    3. Strrpos () -finds the last occurrence of a string in another string (case-sensitive)
    4. Strripos () -finds the last occurrence of a string in another string (case insensitive)
Parameters:
Strripos (string,find,start)
string: Required. Specifies the string to search for.
find: Required. Specifies the character to find.
start: Optional. Specify where to start the search.

Example:

#

<?php
$str =  ' abcdef ';
$find    =  ' abc ';
$pos  = strpos ($mystring,  $findme);

//  Note that this is used  === cannot use = =
//  because if not
The string returns False if the string is at the beginning of the string and returns 0 in order to differentiate between 0 and false, you must use the equivalent operator = = = or! ==

if  ($pos  === false)  {
     echo  "$find not in $str";
} else {
    echo  " $ find In $ str ";
}
?

< Span class= "example-contents" >2#

<?php
$string = ‘abcdef abcdef‘;
$find = strpos($string,‘a‘,1); // $find = 7, 不是 0
?>

Determines whether a character is in a string in PHP

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.