2011-08-09 8 views
0

HI私はMyBBのソースコードを変更しています。PHP preg_replace:次のコードは正確に何をしますか?

次のコードは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); 

それが正確に何をしますか?私は少し正規表現を知っているが、これは少し複雑すぎる。

私にこれを説明できますか?

ありがとうございます!

答えて

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;でそれを付加して交換してください。

のすべての文字列を&#x26;xxxに置き換えます。これは、rssフィード項目にアンパサンド文字を書き込む安全な方法です。

関連する問題