php - Fopen a .txt file using a regex -
i need open .txt file know directory path not entire name. know unique numbers part of name.
i've checked php.net , google little bit didn't find useful.
in opinion possible achieve this?
for example: have these unique numbers part of filename ("9129129"), , know path directory , other files stored ("/home/library/applicationsupport/project"). file .txt, , can "xyz124124 fbqwf9129129 fwehbj$124.txt".
you use glob
function match .txt file sub-string:
$substring = "9129129"; $path = '/home/library/applicationsupport/project/'; list($name) = glob(sprintf("$path*%d*.txt", $substring), glob_nosort) + array(null); if ($name) { $file = fopen($path . $name, "r"); // `$file` }
Comments
Post a Comment