PHP preg_replace:下面的代码具体做什么?
嗨,我正在修改MyBB的源代码 以下代码来自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
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