我需要找到一個文件名是否包含一些我不想要的特殊字符。錯誤:在PHP中的preg_match_all期間沒有重複的偏移量錯誤
我實際使用此代碼:
$files = array("logo.png", "légo.png");
$badChars = array(" ", "é", "É", "è", "È", "à", "À", "ç", "Ç", "¨", "^", "=", "/", "*", "-", "+", "'", "<", ">", ":", ";", ",", "`", "~", "/", "", "|", "!", "@", "#", "$", "%", "?", "&", "(", ")", "¬", "{", "}", "[", "]", "ù", "Ù", '"', "«", "»");
$matches = array();
foreach($files as $file) {
$matchFound = preg_match_all("#\b(" . implode("|", $badChars) . ")\b#i", $file, $matches);
}
if ($matchFound) {
$words = array_unique($matches[0]);
foreach($words as $word) {
$results[] = array('Error' => "Forbided chars found : ". $word);
}
}
else {
$results[] = array('Success' => "OK.");
}
但我有一個錯誤說:
Warning: preg_match_all(): Compilation failed: nothing to repeat at offset 38 in /home/public_html/upload.php on line 138
那就是:
$matchFound = preg_match_all("#\b(" . implode("|", $badChars) . ")\b#i", $file, $matches);
任何幫助或線索?
得到了'解析錯誤:語法錯誤,意外' ,''爲你的第一行。 – poipoi 2015-02-11 14:20:52
答案已經改變,刷新你的瀏覽器。 – 2015-02-11 14:21:46
看起來不錯,但是我找到了'禁止發現的字符:數組',而我想'禁用的字符發現:+'例如。我該如何改變它? – poipoi 2015-02-11 14:24:21