Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP preg_replace:下面的代码具体做什么?_Php_Regex_Mybb - Fatal编程技术网

PHP preg_replace:下面的代码具体做什么?

PHP preg_replace:下面的代码具体做什么?,php,regex,mybb,Php,Regex,Mybb,嗨,我正在修改MyBB的源代码 以下代码来自class\u feedgeneration.php: /** * Sanitize content suitable for RSS feeds. * * @param string The string we wish to sanitize. * @return string The cleaned string. */ function sanitize_content($content) { $content = preg

嗨,我正在修改MyBB的源代码

以下代码来自
class\u feedgeneration.php

/**
 * Sanitize content suitable for RSS feeds.
 *
 * @param  string The string we wish to sanitize.
 * @return string The cleaned string.
 */
function sanitize_content($content)
{
    $content = preg_replace("#&[^\s]([^\#])(?![a-z1-4]{1,10};)#i", "&$1", $content);
    $content = str_replace("]]>", "]]]]><![CDATA[>", $content);

    return $content;
}
它到底做什么?我知道一点正则表达式,但这个有点太复杂了

有人能给我解释一下吗

非常感谢

"#& -- the char & as is
[^\s] -- one not space character (also \S could be used instead)
([^\#]) -- one not-dash character
(?![a-z1-4]{1,10};) -- and negative lookahead assertion that previous chars
                    -- are not followed by chars in a-z1-4 range
                    -- (only 1 to 10 in a row) with ; after
#i" -- case insensitive
我们从所有的匹配中选择
([^\#])
,在前面加上
&并替换

它用于将所有
&xxx
序列替换为
&x26;xxx
这是在rss提要项中写入符号和字符的安全方法

"#& -- the char & as is
[^\s] -- one not space character (also \S could be used instead)
([^\#]) -- one not-dash character
(?![a-z1-4]{1,10};) -- and negative lookahead assertion that previous chars
                    -- are not followed by chars in a-z1-4 range
                    -- (only 1 to 10 in a row) with ; after
#i" -- case insensitive