2017-11-08 8 views
1

에서 함수 이름을 찾기 나는 PHP 함수 이름을 찾기위한 정규 표현식 구문을 쓰고 싶습니다정규 표현식입니다. 예를 들어</p> <p>: PHP

public function _c_Def() 
{ 

} 

내가하고 싶으 :

_c_Def 

무엇 나는 시도 :

/function[\s\n]+(\S+)[\s\n]*\(/ 
(?:^|\n)function ([^\s]+) 

그러나 때마다 내가 솜를 그리워

+0

정규식'함수 [\ S \ 않음] + (\ S +) \ S \ 않음은 * \ ('일 것 : https://regex101.com/r/ tQmEa6/1 –

답변

1

PHP Reflection API를 사용하면 regexp로 구문 분석하는 대신 클래스의 모든 메소드를 가져올 수 있습니다.

$class = new ReflectionClass('Namespace\YourClassName'); 
$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC); 
http://php.net/manual/en/book.reflection.php