Blessed Geek
0
Q:

strpos and stripos in php

It use find the first occurence of string into another string and returns the integer as position of first occurance string.
Syntax:
strpos(original_str, search_str, start_pos)

<?php 
  
// PHP code to search for a specific string's position 
// first occurrence using strpos() case-sensitive function 
function Search($search, $string){ 
    $position = strpos($string, $search, 5);   
    if (is_numeric($position)){ 
        return "Found at position: " . $position; 
    } 
    else{ 
        return "Not Found"; 
    } 
} 
  
// Driver Code 
$string = "Hello all this is Grepper snippet"; 
$search = "Grepper"; 
echo Search($search, $string); 
?> 

It use find the first occurence of string into another string and returns the integer as position of first occurance string.
but stripos is caseinsensitive due to which we only have write the search string it doesn't matters whether is written in small or capital case. 
Syntax:
stripos(original_str, search_str, start_pos)

<?php 
  
// PHP code to search for a specific string's position 
// first occurrence using strpos() case-sensitive function 
function Search($search, $string){ 
    $position = stripos($string, $search, 5);   
    if (is_numeric($position)){ 
        return "Found at position: " . $position; 
    } 
    else{ 
        return "Not Found"; 
    } 
} 
  
// Driver Code 
$string = "Hello all this is Grepper snippet"; 
$search = "grepper"; 
echo Search($search, $string); 
?> 
0

New to Communities?

Join the community