0

您好我正在修改 MyBB 的源代码。

以下代码来自class_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;
}

第一个:

$content = preg_replace("#&[^\s]([^\#])(?![a-z1-4]{1,10};)#i", "&#x26;$1", $content);

它究竟是做什么的?我知道一点正则表达式,但是这个有点太复杂了。

有人可以向我解释一下吗?

非常感谢!

4

1 回答 1

1
"#& -- 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

从我们采取的所有比赛中([^\#]),将其添加&#x26;并替换。

它用于替换所有&xxx序列,&#x26;xxx这是在 rss 提要项中编写 & 字符的安全方式。

于 2011-08-09T23:40:22.780 回答