728x90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$content = 'test(abcd) : test라는 함수에 영문을 인수로, test(123) : 숫자를 인수로...'; | |
$pattern = '/test\((.*?)\)/i'; | |
preg_match_all($pattern, $content, $matches); | |
print_r($matches); | |
/* | |
Array | |
( | |
[0] => Array | |
( | |
[0] => test(abcd) | |
[1] => test(123) | |
) | |
[1] => Array | |
( | |
[0] => abcd | |
[1] => 123 | |
) | |
) | |
*/ |
이런 경우는 없겠지만 억지로 있을 것이라고 가정을 합니다.
위 코드 2번째 줄에 있는 "test(abcd) : test라는 함수에 영문을 인수로, test(123) : 숫자를 인수로..." 이런 문장이 있습니다.
갖고 와야 할 값은 test()라고 하는 함수에 넘기는 인수들을 갖고 와야 합니다. abcd, 123이라는 값이 나오겠지요.
[샘플]
반응형
'Programming > PHP' 카테고리의 다른 글
주말 제외 날짜 계산(excluding weekend) (0) | 2020.12.21 |
---|---|
배열의 key를 기준으로 정렬 (0) | 2020.12.07 |
몫, 나머지 구하기... (0) | 2020.11.13 |
Convert object to array in php (0) | 2020.11.04 |
한글로 요일 표기하기 (0) | 2020.07.29 |