Delete files which has the same prefix

前端 未结 2 398
别那么骄傲
别那么骄傲 2020-12-09 15:46
$prefix = \'something_prefix\';
unlink($prefix.\'.*\');

the code above is not working, but I see some code like this below works just fine

相关标签:
2条回答
  • 2020-12-09 16:21

    You can use glob for this. Something like this(didn't test it):

    foreach (glob("something_prefix*.*") as $filename) {
        unlink($filename);
    }
    
    0 讨论(0)
  • 2020-12-09 16:23

    Try this code:

    $mask = 'your_prefix_*.*';
    array_map('unlink', glob($mask));
    

    p.s. glob() requires PHP 4.3.0+

    0 讨论(0)
提交回复
热议问题