Skip to content

Instantly share code, notes, and snippets.

@maechabin
Last active August 29, 2015 14:15
Show Gist options
  • Save maechabin/0e26dc271349aed14a72 to your computer and use it in GitHub Desktop.
Save maechabin/0e26dc271349aed14a72 to your computer and use it in GitHub Desktop.
指定フォルダから任意のファイル名を取得
<?php
class Get_file_name {
private $dir;
private $pattern;
public $match_word;
function __construct($d, $p) {
$this->dir = $d;
$this->pattern = $p;
}
private function get_file() {
if (is_dir($this->dir) && $dh = opendir($this->dir)) {
while (($file = readdir($dh)) !== false) {
if($this->check_file($file) === true) {
break;
}
}
closedir($dh);
}
}
private function check_file($f) {
preg_match($this->pattern, $f, $matches);
if (isset($matches[1])) {
$this->match_word = $matches[1];
return true;
}
}
public function init() {
$this->get_file();
return $this->match_word;
}
}
$js_file = new Get_file_name("c:\\xampp\\htdocs\\test\\js", "/^function\.min\-([0-9a-z]{32})\.js$/");
echo $js_file->init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment