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;
}

1つ目:

$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;置き換えます。

これは、rss フィード項目にアンパサンド文字を安全に書き込む方法であるすべての&xxxシーケンスを置き換えるために使用されます。&#x26;xxx

于 2011-08-09T23:40:22.780 に答える