PHP Get file name starting with prefix

前端 未结 3 1097
一个人的身影
一个人的身影 2021-01-07 19:10

This is a custom function. At the moment, this function get all the file in the default directory, strip \".php\" and list them.

The problem is that I want to only

3条回答
  •  生来不讨喜
    2021-01-07 19:53

    You need to change the regular expression in preg_grep:

    $files = preg_grep('~^tpl-.*\.php$~', scandir(admin . "templates/default/"));
    

    Explanation:

    1. ^tpl- - starting with "tpl-"

    2. .* - any characters

    3. \.php$ - ending with ".php"

提交回复
热议问题