HI I am modifying the source code of MyBB.
The following code is from 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($开发者_Go百科content)
{
$content = preg_replace("#&[^\s]([^\#])(?![a-z1-4]{1,10};)#i", "&$1", $content);
$content = str_replace("]]>", "]]]]><![CDATA[>", $content);
return $content;
}
The 1st one:
$content = preg_replace("#&[^\s]([^\#])(?![a-z1-4]{1,10};)#i", "&$1", $content);
What does it do exactly? I know a little regex, but this one is a little too complicated.
Could some explain this to me?
Thanks a lot!
"#& -- 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
And from all the match we take ([^\#])
, prepend it with &
and replace.
It is used to replace all &xxx
sequences with &xxx
which is the safe way to write ampersand-char in rss feed item.
精彩评论