|
function_discuzcode.php里面有两种替换标签的方式:
第一种是139~172行
- $message = str_replace(array(
- '[/color]', '[/backcolor]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', '[s]', '[/s]', '[hr]', '[/p]',
- '[i=s]', '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
- '[list=A]', "\r\n[*]", '[*]', '[/list]', '[indent]', '[/indent]', '[/float]'
- ), array(
- '</font>', '</font>', '</font>', '</font>', '</div>', '<strong>', '</strong>', '<strike>', '</strike>', '<hr class="l" />', '</p>', '<i class="pstatus">', '<i>',
- '</i>', '<u>', '</u>', '<ul>', '<ul type="1" class="litype_1">', '<ul type="a" class="litype_2">',
- '<ul type="A" class="litype_3">', '<li>', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>'
- ), preg_replace(array(
- "/\[color=([#\w]+?)\]/i",
- "/\[color=((rgb|rgba)\([\d\s,]+?\))\]/i",
- "/\[backcolor=([#\w]+?)\]/i",
- "/\[backcolor=((rgb|rgba)\([\d\s,]+?\))\]/i",
- "/\[size=(\d{1,2}?)\]/i",
- "/\[size=(\d{1,2}(\.\d{1,2}+)?(px|pt)+?)\]/i",
- "/\[font=([^\[\<]+?)\]/i",
- "/\[align=(left|center|right)\]/i",
- "/\[p=(\d{1,2}|null), (\d{1,2}|null), (left|center|right)\]/i",
- "/\[float=left\]/i",
- "/\[float=right\]/i"
- ), array(
- "<font color=\"\\1\">",
- "<font style=\"color:\\1\">",
- "<font style=\"background-color:\\1\">",
- "<font style=\"background-color:\\1\">",
- "<font size=\"\\1\">",
- "<font style=\"font-size:\\1\">",
- "<font face=\"\\1\">",
- "<div align=\"\\1\">",
- "<p style=\"line-height:\\1px;text-indent:\\2em;text-align:\\3\">",
- "<span style=\"float:left;margin-right:5px\">",
- "<span style=\"float:right;margin-left:5px\">"
- ), $message));
复制代码
第二种是181~186行:
- if(strpos($msglower, '[/quote]') !== FALSE) {
- $message = preg_replace("/\s?\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s?/is", tpl_quote(), $message);
- }
- if(strpos($msglower, '[/free]') !== FALSE) {
- $message = preg_replace("/\s*\[free\][\n\r]*(.+?)[\n\r]*\[\/free\]\s*/is", tpl_free(), $message);
- }
复制代码
容易看出,第一种是分别替换开标签与闭标签, 而第二种是将开标签与闭标签配对再替换.
第一种的效果是
- ...text 1...[color=red]...text 2...
复制代码
会被替换为
- ...text 1...<font color="red">...text 2...
复制代码
不论text 2中是否包含[/color].
而第二种的效果是
- ...text 1...[quote]...text 2...
复制代码
只有当text2中包含[/quote]时,才会被替换. |
|