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

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

相关文章

获取zblog用户目录 zb_users目录 实际物理路径地址 怎么获取

$upload_dir = $zbp->usersdir . $upload->Dir;  # G:/phpstudy...

php 函数 array_flip()  是干啥的

php 函数 array_flip() 是干啥的

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

(phpsession)php session 增改删的例子 名字叫 baijiahao

当使用 PHP 会话(session)来存储、修改和删除名为 baijiahao 的数据时,你可以按照以下步骤进行操作:启动会话首先,你需要在每个需要使用会话的 PHP 脚本中启动会话。这通常是通过调...

ai提示词  创建 文章大纲构  xml格式 骨架

ai提示词 创建 文章大纲构 xml格式 骨架

你是一个专业的文章大纲构建专家,根据给你提供的信息创建一个内容大纲出来。要求:围绕主题展开,并适当的进行扩展,并避免重复。在构建大纲时,理解提供的关键词,并深入的展开关键词相关的需求。在构建大纲时请考...

brotli 命令行工具 在centos 和 Ubuntu 分别怎么安装

在CentOS和Ubuntu上安装brotli命令行工具,可以按照以下步骤进行:在CentOS上安装brotli更新系统(可选但推荐):首先,确保你的CentOS系统已经更新到最新状态。bash复制代...