검색으로 배열에서 특정 데이터 가져오기 (get specific datas from a array by a search)


문제 설명

검색으로 배열에서 특정 데이터 가져오기 (get specific datas from a array by a search)

여기에 다양한 데이터가 있는 배열이 있습니다. 서버에서 데이터를 가져옵니다.

 $sp_bots = shell_exec("grep bot | awk '{print $12}' /var/www/laravel/logs/vhosts/website");

이 주석에서 '봇'이라는 단어가 있는 모든 데이터를 가져옵니다. awk

Mozilla/5.0 [82] => "Mozilla/5.0 [83] => "Googlebot‑Image/1.0" [84] => "Googlebot‑Image/1.0" [85]

지금 얻을 수 있는 것은

하지만 저는 '봇'이 발견된 데이터만 원합니다! 난 그냥 어떻게 .. array_filter가 그것을 만들 수 있지만 방법을 모르고 구문을 이해하지 못합니다.


참조 솔루션

방법 1:

If you get an array something like below then Try PHP strpos function

$sp_bots= array( 82 => "Mozilla/5.0", 83 => "Googlebot‑Image/1.0", 84 => "Googlebot‑Image/1.0" );
foreach($sp_bots as $data) {
    if(strpos($data, 'bot' ) > ‑1 ) {
      // It does contain bot string
      echo $data .' contains bot string <br/>';//while it will print the other two indexes
    } else {
      // It does not contain bot value
      echo $data .' does not contains bot string <br/>'; //Mozilla/5.0 does not contain bot string
    }
}

(by Evolution48Basheer Kharoti)

참조 문서

  1. get specific datas from a array by a search (CC BY‑SA 2.5/3.0/4.0)

#PHP #Laravel






관련 질문

bash의 rsync가 php 생성 --exclude-from 파일을 구문 분석하지 않음 (rsync in bash not parsing php-generated --exclude-from file)

PHP 배열 값 저장 (PHP Save array value)

검색으로 배열에서 특정 데이터 가져오기 (get specific datas from a array by a search)

창 서비스를 사용하여 PHP 파일 트리거 (Trigger a php file using window service)

yii2 컨트롤러 작업 주입은 어떻게 작동합니까? (How does the yii2 Controller action injection works)

php와 drupal을 사용하여 pdf를 텍스트로 변환 (pdf to text convert using php and drupal)

PHP에서 카테고리 및 하위 카테고리 목록 검색 (Retrieve Category & Subcategory list in PHP)

PDO - COUNT(*) 결과를 얻습니까? (PDO - get the result of a COUNT(*)?)

PHP - MySQL 쿼리 문제 (PHP - Mysql query problem)

제품용 Reviews.io API의 Foreach 루프 (Foreach loop in Reviews.io API for Products)

숫자를 나누고 점 뒤에 하나의 숫자를 유지하십시오. (Split the number and keep one number after the dot)

내 메시지 입력이 데이터베이스에 들어가지 않습니다. (My message input doesn't get into database)







코멘트