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

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



参考 

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

相关文章

宝塔升级到最新版 python升级 重新执行更新命令,重新安装面板使用的python环境,此操作不会对您的网站、数据库等造成影响,仅仅是针对面板使用的环境修复。

1、将当前Python环境做个备份的操作mv /www/server/panel/pyenv/ /www/backup/pyenv_backup2、重新执行更新命令,重新安装面板使用的python环境...

苹果cms采集python代码 影视采集

苹果cms采集python代码 影视采集qq邮箱搜索 苹果cms采集python代码...

php 大写转小写 小写转大写 大小写转换 例子 strtolower strtoupper

在 PHP 中,可以使用内置的函数来转换字符串的大小写。以下是几个例子:大写转小写:使用 strtolower() 函数将大写字母转换为小写字母。   <...

mysql 优化表 表优化 OPTIMIZE

定期运行数据库维护任务,如  OPTIMIZE TABLE zbp_post ANALYZE TABLE zbp_post ,以保持...

brotli命令行 压缩和 解压缩命令

brotli压缩:brotli -q 11 1.txt -o 1.txt.br   // 压缩 1.txt 为1.txt.br  压缩等级为11级brotli 1.txt -o 1...

http?https?相对协议? // 相对协议  相对协议的主要作用是根据当前页面的协议(HTTP或HTTPS)来自动选择使用哪个协议来加载资源。

http?https?相对协议? // 相对协议 相对协议的主要作用是根据当前页面的协议(HTTP或HTTPS)来自动选择使用哪个协议来加载资源。

相对协议的主要作用是根据当前页面的协议(HTTP或HTTPS)来自动选择使用哪个协议来加载资源。当你在HTML中使用一个以//开头的URL时,浏览器会检查当前页面是通过HTTP还是HTTPS加载的,并...