[英]php list of all defined functions name contains or starts with specific string
我需要所有已定義函數的列表,函數名稱中包含特定字符串
示例:我想獲取文件中所有具有"special_pdf"
字符串的函數名稱的字符串,例如-
special_pdf_a4()
special_pdf_a5()
special_pdf_16()
special_pdf_97()
special_pdf_same_same_example()
當前正在使用此代碼-
$commandList = get_defined_functions();
$funcList = array();
$containText = 'special_pdf';
if(isset($commandList['user'])){
$user_defined_functions = $commandList['user'];
foreach($user_defined_functions as $user_defined_function){
if(substr($user_defined_function, 0, strlen($containText)) === $containText){
$funcList[] = $user_defined_function;
}
}
}
print_r($funcList);
這是找出沒有性能缺陷的正確方法嗎?
快速可能是這個解決方案
$funcs = get_defined_functions();
if(isset($funcs['user']) {
funcList = preg_grep('/special_pdf.*/',$funcs['user']);
print_r($funcList);
}
根據您的需要,您可能需要使用正則表達式模式進行一些玩耍。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.