![]() |
#2
redice2009-12-22 18:43
|

// 以下代码摘自Discuz 7 的discuzcode.func.php文件部分代码
if(strpos($msglower, '[/email]') !== FALSE) {
$message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "parseemail('\\1', '\\4')", $message);
}
function parseemail($email, $text) {
if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) {
$email = trim($matches[0]);
return '<a href="mailto:'.$email.'">'.$email.'</a>';
} else {
return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>';
}
}
if(strpos($msglower, '[/email]') !== FALSE) {
$message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "parseemail('\\1', '\\4')", $message);
}
function parseemail($email, $text) {
if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) {
$email = trim($matches[0]);
return '<a href="mailto:'.$email.'">'.$email.'</a>';
} else {
return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>';
}
}
为什么我仿照那样使用却不行呢?

// 下面是我的代码,请将【换成"[",】换成"]"
<?php
echo $message = preg_replace("/\[email=(([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/is", "parseemail('\\1','\\4')","【email=redice@】redice【/email】");
function parseemail($email, $text) {
if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) {
$email = trim($matches[0]);
return '<a href="mailto:'.$email.'">'.$email.'</a>';
} else {
return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>';
}
}
?>
<?php
echo $message = preg_replace("/\[email=(([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/is", "parseemail('\\1','\\4')","【email=redice@】redice【/email】");
function parseemail($email, $text) {
if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) {
$email = trim($matches[0]);
return '<a href="mailto:'.$email.'">'.$email.'</a>';
} else {
return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>';
}
}
?>
程序输出为: parseemail('redice@','redice')
不要告诉我让我把"parseemail('\\1','\\4')"的双引号去掉。

在线等高手指点
[ 本帖最后由 redice 于 2009-12-22 21:50 编辑 ]