파일에 사용된 변수명 추출
<?php
$id = 'BiHon';
$pw = '1234';
$url = 'http://bihon.com/';
list($year,$month,$day) = explode(' ',date('Y n j')); // 년, 월, 일
?>
$id = 'BiHon';
$pw = '1234';
$url = 'http://bihon.com/';
list($year,$month,$day) = explode(' ',date('Y n j')); // 년, 월, 일
?>
위와 같은 test.php 파일이 있다고 했을 때 여기에서 변수만 뽑는 방법은?
<xmp><?php
preg_match_all('/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',file_get_contents('./test.php'),$matches);
$matches = array_values(array_unique($matches[0]));
?></xmp>
preg_match_all('/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/',file_get_contents('./test.php'),$matches);
$matches = array_values(array_unique($matches[0]));
?></xmp>
변수명 규칙(보러 가기)에 맞는 문자열만 가져오는 것입니다. 실행 결과는 다음과 같습니다.
Array
(
[0] => $id
[1] => $pw
[2] => $url
[3] => $year
[4] => $month
[5] => $day
)
(
[0] => $id
[1] => $pw
[2] => $url
[3] => $year
[4] => $month
[5] => $day
)
함께 나눈 이야기
댓글댓글 남기기