User Tools

Site Tools


uphp:functions:strpos

strpos

WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0

Return the position of the first occurrence of a needle in a haystack

Description

int strpos ( string $haystack, string $needle )

This function will find the numeric position of the first occurrence of a substring (needle) in a string (haystack)

Parameters

$haystack: The string to search in

$needle: The string to search for

Return Values

Integer: Position of where the needle exists relative to the beginning of the haystack string, or -1 if not found.

Note that string positions start at 0, and not 1.

Example

<?
  $str='abcdefabcdef';
  $pos=strpos($str,'abc')
  if ($pos>=0) {
    print("Substring found at position ".$pos); // 0
  }
?>

See Also

charat() - Return the ASCII code for a character in a string at an index

strlen() - Return the length of a string

strrpos() - Return the position of the last occurrence of a needle in a haystack

strtolower() - Return the lowercase version of a string

strtoupper() - Return the UPPERCASE version of a string

substr() - Return part of a string

ucfirst() - Convert a string to lowercase except for the first character

uphp/functions/strpos.txt · Last modified: 2021/09/13 05:57 (external edit)