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

본문 바로가기
사이트 내 전체검색

개발

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

페이지 정보

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

본문

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

댓글목록

등록된 댓글이 없습니다.

Total 386건 3 페이지
  • RSS

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.