Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

str_contains()

Test whether a byte substring appears anywhere, with case sensitivity and no numeric offset result.

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

Syntax

str_contains(string $haystack, string $needle): bool

Test whether a byte substring appears anywhere, with case sensitivity and no numeric offset result. An empty needle is contained in every string, including the empty string. This avoids mistaking a match at byte zero for a failed search.

Signature

str_contains(string $haystack, string $needle): bool

Example output

[true,false,true,true]

Examples

<?php
echo json_encode([str_contains("Log.txt","Log"),str_contains("Log.txt","log"),str_contains("",""),str_contains("id","")]);

Result

[true,false,true,true]

Sources