PHP 의 strpos 함수에서 검색하는 문자열을 배열로 검색하기 > 개발

본문 바로가기

사이트 내 전체검색

뒤로가기 개발

PHP 의 strpos 함수에서 검색하는 문자열을 배열로 검색하기

페이지 정보

작성자 관리자 (114.♡.85.207) 작성일 16-04-02 22:03 조회 3,837 댓글 0

본문

Using an array as needles in strpos


function strposa($haystack, $needle, $offset=0) {
    if(!is_array($needle)) $needle = array($needle);
    foreach($needle as $query) {
        if(strpos($haystack, $query, $offset) !== false) return true; // stop on first true result
    }
    return false;
}
$string = 'Whis string contains word "cheese" and "tea".';
$array  = array('burger', 'melon', 'cheese', 'milk');
var_dump(strposa($string, $array)); // will return true, since "cheese" has been found



** 출처 : http://stackoverflow.com/questions/6284553/using-an-array-as-needles-in-strpos

추천0

댓글목록 0

등록된 댓글이 없습니다.

전체 386건 3 페이지
게시물 검색
Copyright © Baragi.Net All rights reserved.
PC 버전으로 보기