0
我在函數中使用preg_match
來阻止提交圖像擴展! 現在我想阻止「〜」字符也! 任何人都可以告訴我我該怎麼做?爲什麼這種模式在preg_match中不起作用
function is_valid($url) {
$res = 1;
if (isset($url['path'])) {
if (preg_match('/\b.jpg\b/i', $url['path'])) { $res = 0; }
if (preg_match('/\b.gif\b/i', $url['path'])) { $res = 0; }
if (preg_match('/\b.png\b/i', $url['path'])) { $res = 0; }
if (preg_match('/\b.bmp\b/i', $url['path'])) { $res = 0; }
}
return $res;
}
我嘗試這樣做,但它不工作:
if (strpos('~', $url['path'])) {
$res = 0;
}
哇!你的代碼有效:) 謝謝你花時間回答這個愚蠢的問題。我非常感謝幫助。 我只是一個新手,並試圖學習編碼!我一定會按照你的指示! 再次感謝你:) @Michael –