0

I want to create a php script which finds all files with name favicon_323123.ico. Of course, string _323123 is not static.

This is my current code:

<?php
$filepath = recursiveScan('/public_html/wp-admin/');
$text = 'favicon' .*. 'ico'

function recursiveScan($dir) {
    $tree = glob(rtrim($dir, '/') . '/*');
    if (is_array($tree)) {
        foreach($tree as $file) {
            if (is_dir($file)) {
                //echo $file . '<br/>';
                recursiveScan($file);
            } elseif (is_file($file)) {
               if (strpos($file, $text) !== false) {
                   echo $file . '<br/>';
                   //unlink($file);
               }
                
            }
        }
    }
}
?>
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Adam Kowalski
  • 103
  • 13

1 Answers1

0

From

if (strpos($file, $text) !== false) {

To

if (preg_match( "/favicon_[0-9]+\.ico$/", $file )) {

The preg_match call, checks if the file is the file you're looking for or not.

Karlo Kokkak
  • 3,674
  • 4
  • 18
  • 33