Jump to: navigation, search

Php stripos

From w3cyberlearnings

Contents

PHP function stripos

This function finds the first occurence of a string within another string and this function is a case insensitive.

Syntax stripos

  • string: string input.
  • find: string to find.
  • startpos: specifies where the search to begin.
stripos(string, find, startpos);

Return

Return the first position of the string.

Example 1

<?php
echo stripos("Leader is a person who serve others.", "person");
?>

Output

12

Example 2

<?php

echo stripos("Leader is a person who serve others.", "PERSON");
?>

Output

12

Example 3: Search Multiple Keys

<?php
// List of key to search
$find_keys = "Girl boy human woman husband"; 
   
$str_content = 
   "A girl knows that boy, and that man is the woman husband. All human beging";

$array_found = array();

foreach (explode(" ", $find_keys) as $key) {
	$array_found[$key] = stripos($str_content, $key);
}
/////////////
foreach ($array_found as $key => $search_pos) {
	echo $key . ' is at ' . $search_pos . '<br/>';
}
?>

Output

Girl is at 2
boy is at 18
human is at 62
woman is at 43
husband is at 49

Related Functions


Navigation
Web
SQL
MISC
References