我在与个人论坛共同撰写的网站上为我个人论坛撰写了短文功能。
引出的标语见[引用=用户名]message[/quote]
,因此我写道:
$str=preg_replace( #[quote=(.*?)](.*?)[/quote]#is , <div class="messageQuoted"><i><a href="index.php?explore=userview&userv=$1">$1</a> wrote :</i>$2</div> , $str);
如果报价是一例,但用户则引用该笔意向书。 因此,我需要一种“
I tried to searching on SO many topics, but I don t really understand how it can works. Would be appreciated any suggestions/tips for do this kind of operation! Let me know, and thanks!
EDIT
At the end, this is my own solution :
if(preg_match_all( #[quote=(.*?)](.*?)#is , $str, $matches)==preg_match_all( #[/quote]#is , $str, $matches)) {
array_push($format_search, #[quote=(.*?)](.*?)#is );
array_push($format_search, #[/quote]#is );
array_push($format_replace, <div class="messageQuoted"><a class="lblackb" href="index.php?explore=userview&userv=$1">$1</a> wrote :<br />$2 );
array_push($format_replace, </div> );
}
$str=preg_replace($format_search, $format_replace, $str);
it repleace only if the number of occurences is correct. So it should (right?) to prevent html broke or other malicious attack. What do you think?