2016-06-06 4 views
1

나는 누군가가 그렇게하기를 원합니다! 속삭임 예제 이것은 테스트 예입니다.문자열의 다른 부분을 확인하고 얻는 방법

그것은 것 출력 "예" "이 시험 예이다"등 & $whispermessage 같은 $whisperuser.

<?php 
    if (strpos($message, '!whisper') === 0) { 
     $arr = explode(' ',trim($message)); 
     $whisperuser = $arr[1]; 
     $whispermessage = $arr[2]; // I need Whisper message to be anything arr[2] and HIGHER. 
     // WOULD DO OUTPUT STUFF HERE 
    } 
?> 

답변

0

코드를 쉽게 작성할 수 있습니다. 폭발하는 제 3 인수를 추가 한 후에는 마지막 항목이에 대한

list(, $whisperuser, $whispermessage) = explode(' ',trim($message), 3); 

demo

0

사용는 preg_match에 문자열의 나머지 부분을 넣어 것입니다. 가정하면 사용자는 이름이 종료 어디

$str = '!whisper EXAMPLE this is a test example'; 

$matches = []; 

preg_match("/!whisper\s(\w+)\s(.*)$/", $str, $matches); 

if (!empty($matches[1]) && !empty($matches[2])) { 
    echo "Wispering to user {$matches[1]}: '{$matches[2]}'"; 
} else { 
    echo "No actions taken!"; 
} 

PHP Snippet


사용자가 이름 공간을 가질 수 있습니다 경우 RegEx example, 당신은 어떻게 든 지정해야보다 이름의 공간을 가질 수 없습니다. 사용자 some user이있는 경우 예를 들어 some user new으로 속삭임으로 인해 불가능할 수 있습니다.

관련 문제