1
假設我的目錄上有一個名爲table.pdf
的文件,並且我試圖使用字符串table
作爲搜索條件進行搜索。我試圖使用和table
作爲我的$pattern
,但這不會返回匹配,而使用table.pdf
作爲$pattern
返回匹配。示例使用fnmatch的文件名字符串搜索()
$table = 'table';
$table_2 = 'table.pdf';
if (fnmatch($table, $pdf)){
// No Match found
}
if (fnmatch($table_2, $pdf)){
// Match Found
}
如何解決此問題?
嗨,根據文檔,**模式**是一個像字符串的shell,如果你想使用第一種模式,你應該去:「table *」如果你想匹配所有「表「文件。如果你的意思是有一個通用的PDF字符串,你應該去「* .pdf」。 –