我目前使用這一段代碼通過去除,以減少給定文本到一個有效的「標籤」格式(僅小寫,AZ和減去允許)/替換無效字符優化「標記」的正則表達式
$zip_filename = strtolower($original);
$zip_filename = preg_replace("/[^a-zA-Z\-]/g", '-', $zip_filename); //replace invalid chars
$zip_filename = preg_replace("/-+/g", '-', $zip_filename); // reduce consecutive minus to only one
$zip_filename = preg_replace("/^-/g", '', $zip_filename); // removing leading minus
$zip_filename = preg_replace("/-$/g", '', $zip_filename); // remove trailing minus
不限提示如何把至少正則表達式放入一個單一的?
感謝您的任何建議!
爲什麼不會$ zip_filename = preg_replace(「/ [^ a-zA-Z \ - ]/g」,'',$ zip_filename); //用無效 工作替換無效字符? – murgatroid99 2010-07-07 20:57:26