php文件名字 去掉特殊字符 zblog实现
FormatString($article->Title, '[filename]')
zb_system/function/c_system_common.php
/**
* 格式化字符串.
*
* @param string $source 字符串
* @param string $para 正则表达式,可用[html-format]|[nohtml]|[noscript]|[enter]|[noenter]|[filename]|[normalname]或自定义表达式
*
* @return string
*/
function FormatString($source, $para)
{
if (strpos($para, '[html-format]') !== false) {
$source = htmlspecialchars($source);
//if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
// $source = htmlspecialchars($source, (ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE), "UTF-8");
//} else {
// $source = htmlspecialchars($source, ENT_COMPAT, "UTF-8");
//}
}
if (strpos($para, '[nohtml]') !== false) {
$source = preg_replace("/<([^<>]*)>/si", "", $source);
$source = str_replace("<", "˂", $source);
$source = str_replace(">", "˃", $source);
}
if (strpos($para, '[noscript]') !== false) {
$class = new XssHtml($source);
$source = trim($class->getHtml());
}
if (strpos($para, '[enter]') !== false) {
$source = str_replace("\r\n", "<br/>", $source);
$source = str_replace("\n", "<br/>", $source);
$source = str_replace("\r", "<br/>", $source);
$source = preg_replace("/(<br\/>)+/", "<br/>", $source);
}
if (strpos($para, '[noenter]') !== false) {
$source = str_replace("\r\n", "", $source);
$source = str_replace("\n", "", $source);
$source = str_replace("\r", "", $source);
}
if (strpos($para, '[filename]') !== false) {
$source = str_replace(array("/", "#", "$", "\\", ":", "?", "*", "\"", "<", ">", "|", " "), array(""), $source);
}
if (strpos($para, '[normalname]') !== false) {
$source = str_replace(array("#", "$", "(", ")", "*", "+", "[", "]", "{", "}", "?", "\\", "^", "|", ":", "'", "\"", ";", "@", "~", "=", "%", "&"), array(""), $source);
}
return $source;
}参考

