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

zblog12个月前zblog问题解答35
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 

相关文章

php 变量保存为字符串 序列化和反序列化

<?php // 定义一个数组变量 $array = array('apple', 'banana', &#...

mkdir -p /www/server/panel/data/firewall

mkdir -p /www/server/panel/data/firewall 是一个在 Linux 或 Unix 系统上创建目录的命令。让我们分解一下这个命令的各个部分:mkdir: 这是用于创建...

php 函数 array_flip()  是干啥的

php 函数 array_flip() 是干啥的

flip 英文意思是 快速反转,顾名思义,array_flip 就是把 键值对的 键和值 反转,因为键 是唯一的,所以反转后 如果重复取第一个。`array_flip` 是 PHP 中的一个函数,用于...

linux伪静态 (大括号转义)

linux伪静态 (大括号转义)

大括号转义问题: Nginx配置文件中,大括号{}默认用于配置块(如server{}),直接用在正则表达式中会被误解析。 解决方案:用单引号包裹正则表达式(推荐),或转义大括号(但转义可能不生效,...

python 定时任务 计划任务 宝塔python 项目 宝塔python配置

python 定时任务 计划任务 宝塔python 项目 宝塔python配置

查看python 版本 在命令行 输入 : python1建立python 项目查看pip 模块版本 如 pip show requests====================程序可以正...

正则表达式的替换的花招

1 $url = preg_replace_callback("|{&([a-zA-Z0-9]+)\=%|", "UrlRule:...