php文件名字 去掉特殊字符 zblog实现

zblog1年前zblog问题解答79
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;
}



参考 

https://zblog.gongshi5.com/post/156.html 

相关文章

cat /root/.bash_history root 用户的命令历史记录。

root 用户的历史命令记录,可以使用以下命令:cat /root/.bash_history这个命令会显示 /root/.bash_history 文件中的内容,即 root 用户的命令历史记录。...

mysql创建给指定数据库创建账户密码

-- 假设你已经登录到了 MySQL 数据库管理系统中 -- 1. 创建用户 CREATE USER 'z...

phpstorm中的正则表达式替换 编辑器IDE

phpstorm中的正则表达式替换 编辑器IDE

phpstorm中的正则表达式替换 编辑器IDE...

html中 &#20320;&#22909; 中 &# ;是啥意思20320 又是啥意思 字符实体引用(Character Entity Reference)

在HTML中,&#xxxx; 是一种字符实体引用(Character Entity Reference)的表示方法,用于在网页中插入那些无法直接在HTML代码中表示的字符。这里的&n...

zblog常用简写

print_r($zbp->currenturl); # 当前url 路径 访问 www.zblog.cn/post/123.html 就是 ...

zblog链式sql不支持 ESCAPE  ,但是sqlite 必须要用ESCAPE ,硬改sql不优雅了

zblog链式sql不支持 ESCAPE ,但是sqlite 必须要用ESCAPE ,硬改sql不优雅了

/zb_system/function/lib/zblogphp.php通过用户名获取用户实例(不区分大小写). public function GetMemberByN...