다음 문자열이 있습니다. 예 : 'Hello [owner], we could not contact by phone [phone], it is correct?'
.
Regex는 배열 형식으로 반환하고 싶습니다 []
. 대괄호 안에는 알파벳 문자 만 있습니다.
반환:
$array = [
0 => '[owner]',
1 => '[phone]'
];
이 반환을 PHP로 진행하려면 어떻게해야합니까?
시험:
$text = 'Hello [owner], we could not contact by phone [phone], it is correct?';
preg_match_all("/\[[^\]]*\]/", $text, $matches);
$result = $matches[0];
print_r($result);
산출:
Array
(
[0] => [owner]
[1] => [phone]
)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다