Change language

PHP Strpos () and stripos () Functions

This function helps us find the position of the first occurrence of a string in another string. This returns an integer value for the position of the first occurrence of the string. This function is case sensitive , which means it treats upper and lower case characters differently.Syntax:
 strpos (original_str, search_str, start_pos)
Parameters used :
Of the three parameters specified in the syntax, two are required and one - optional. The three parameters are described below:
  • original_str (required):this parameter refers to the original string in which we need to search for an occurrence of the required string.
  • search_str (required):this parameter refers to the line we need to find.
  • start_pos (optional): pointsto the line position from which to start search.
  • Return type : This function returns an integer value that represents the index original_str, in which the string search_str first appears.Example:  
    // PHP code to find the position of a specific line
    / / first appearance using case sensitive for the strpos() function function Search ( $search , $string ) { $position = strpos ( $string , $search , 5); if ( $position == true) { return "Found at position:" . $position ; } else { return "Not Found" ; } }  
    // Driver code $string = "Welcome to GeeksforGeeks" ; $search = "Geeks" ; echo Search ( $search , $string ); ?>
    Output:
    Found at position 11
    stripos() in PHP This function also helps us find the position of the first occurrence of a string on another line. This returns an integer value for the position of the first occurrence of the string. This function is case insensitive , which means that it handles both uppercase and lowercase letters the same. This function works the same as strpos(), the difference is that it is case sensitive, whereas strpos() is case sensitive.Syntax:
    stripos (original_str, search_str, start_pos)
    Parameters used :
    Of the three parameters specified in the syntax, two are required and one optional
  • original_str (required):this parameter refers to the original string where we need to search for an occurrence of the required string.
  • search_str (required):this parameter refers to the string we need to find.
  • start_pos (optional):this parameter refers to the position of the string where the search should start. Return type : This function returns an integer value that represents the index original_str at where the string search_str first appears.Example:
    // PHP code to find a specific string
    // first occurrence using stripos() case insensitive function Search ( $search , $string ) { $position = stripos ( $string , $search , 5); if ( $position == true) { return "Found at posiion" . $position ; } else { return "Not Found" ; } }  
    // Driver code $string = "Welcome to GeeksforGeeks" ; $search = "engineer" ; echo Search ( $search , $string ); ?>
    Output:
    Found at position 11
  • Shop

    Learn programming in R: courses

    $

    Best Python online courses for 2022

    $

    Best laptop for Fortnite

    $

    Best laptop for Excel

    $

    Best laptop for Solidworks

    $

    Best laptop for Roblox

    $

    Best computer for crypto mining

    $

    Best laptop for Sims 4

    $

    Latest questions

    NUMPYNUMPY

    Common xlabel/ylabel for matplotlib subplots

    12 answers

    NUMPYNUMPY

    How to specify multiple return types using type-hints

    12 answers

    NUMPYNUMPY

    Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

    12 answers

    NUMPYNUMPY

    Flake8: Ignore specific warning for entire file

    12 answers

    NUMPYNUMPY

    glob exclude pattern

    12 answers

    NUMPYNUMPY

    How to avoid HTTP error 429 (Too Many Requests) python

    12 answers

    NUMPYNUMPY

    Python CSV error: line contains NULL byte

    12 answers

    NUMPYNUMPY

    csv.Error: iterator should return strings, not bytes

    12 answers


    Wiki

    Python | How to copy data from one Excel sheet to another

    Common xlabel/ylabel for matplotlib subplots

    Check if one list is a subset of another in Python

    sin

    How to specify multiple return types using type-hints

    exp

    Printing words vertically in Python

    exp

    Python Extract words from a given string

    Cyclic redundancy check in Python

    Finding mean, median, mode in Python without libraries

    cos

    Python add suffix / add prefix to strings in a list

    Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

    Python - Move item to the end of the list

    Python - Print list vertically