0
이 방법을 간소화하려고합니다. 그것은 기본적으로 액션 (문자열)을 받아 들여 camelCase에 대시/밑줄을 긋고 그 결과가 네이티브 PHP 함수와 같은지 테스트합니다. 그렇다면 앞에 밑줄이옵니다. 이 모든 것이 하나의 정규식이 될 수 있다고 생각하지만 function_exists를 테스트하는 방법을 모르겠습니다. 어떤 도움이라도 대단히 감사합니다!PHP : 기본 PHP 함수에 대해 파선/밑줄 문자 및 테스트 결과를 camelcase하는 정규식이 필요합니다.
public function getMethod($action){
if (strpos($action, '-') !== false){
$action = str_replace(' ', '', ucwords(str_replace('-', ' ', $action)));
$action = lcfirst($action);
}
if (strpos($action, '_') !== false){
$action = str_replace(' ', '', ucwords(str_replace('_', ' ', $action)));
$action = lcfirst($action);
}
// resolves native function names with underscore
if (function_exists($action)) return "_".$action;
else if ($action == 'list') return '_list';
else if ($action == 'new') return '_new';
else if ($action == '') return 'index';
else return $action;
}
지금 예상대로이 일을합니까? – hookedonwinter
네, 물론 그렇지 않습니다. – shanebo