Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

strpos()

Locate the first case-sensitive byte match or return false.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

strpos(string $haystack, string $needle, int $offset = 0): int|false

Locate the first case-sensitive byte match or return false. A successful match at the start returns integer zero, so compare failure strictly. A negative offset starts the search that many bytes from the end. Offsets outside the permitted range throw ValueError.

Signature

strpos(string $haystack, string $needle, int $offset = 0): int|false

Example output

[0,3,false,false]

Examples

<?php
$s="ab-ab"; echo json_encode([strpos($s,"ab"),strpos($s,"ab",-2),strpos($s,"AB"),strpos($s,"ab")===false]);

Result

[0,3,false,false]

Sources