我正在为下面的聊天对话框进行格式化:
- Dalvik: Lorem ipsum dolor sit amet
- Jenni:Suspendisse facilisis pretium ante,
- Dalvik: Vivamus feugiat dui ut libero rhoncus nec porttitor velit posuere。
- Jenni: Aenean porttitor ipsum eu metus adipiscing
- Dalvik: (Sed vehicula: magna vitae nulla
- Jenni: sed dui quam, vitae consectetur dui。
- Jenni: Curabitur vulputate ante :)
上面的粗体字; 它在我的替换语句中出错:
$name = self::getNameFromMessage($textFormat);
$color = self::getNewTextColor();
$replacement = "<br/><font color='$color'>$name</font>:";
$textFormat = preg_replace(
$pattern = "/$name :\s/i", //find $name in $textFormat and set text color
$replacement,
$subject = $textFormat
);
错误:preg_replace() [function.preg-replace]: Compilation failed: missing ) at offset 15
你能建议我一个更好的正则表达式字符串吗?