IT/PHP | CI

[PHP] strpos함수로 특정 키워드(문자열) 포함 여부 체크하기

카제인나트륨. 2023. 7. 4. 11:39
728x90
반응형
설명

 

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

 

(PHP 4, PHP 5, PHP 7, PHP 8)

strpos  문자열에서 하위 문자열이 처음 나타나는 위치를 찾음

 

출처

 

PHP: strpos - Manual

A pair of functions to replace every nth occurrence of a string with another string, starting at any position in the haystack. The first works on a string and the second works on a single-level array of strings, treating it as a single string for replaceme

www.php.net

 

 

소스

 

$string = 'hello Fubao'; 
$search = "Fubao";  

if(strpos($string, $search) !== false)   
    echo "존재합니다";	
else 
    echo "존재하지 않습니다";

 

728x90
반응형