【发布时间】:2017-01-04 10:53:05
【问题描述】:
我有一个功能
function showBBcodes($text) {
// BBcode array
$find = array(
'~\[b\](.*?)\[/b\]~s',
'~\[i\](.*?)\[/i\]~s',
'~\[u\](.*?)\[/u\]~s',
'~\[quote\](.*?)\[/quote\]~s',
'~\[size(.*?)\=(.*?)\](.*?)\[/size\]~s',
'~\[color(.*?)\=(.*?)\](.*?)\[/color\]~s',
'~\[url\]((?:ftp|https?)://.*?)\[/url\]~s',
'~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s',
'~\[b_id\](.*?)\[/b_id\]~s',
'~\[tex\](.*?)\[/tex\]~s',
'~\[sup\](.*?)\[/sup\]~s'
);
// HTML tags to replace BBcode
$replace = array(
'<span stype="font-weight: bold;"> $1</span>',
'<i>$1</i>',
'<span style="text-decoration:underline;">$1</span>',
'<pre>$1</'.'pre>',
'<span style="font-size:$2px;">$3</span>',
'<span style="color:$2;">$3</span>',
'<a class="blue-font" href="$1">$1</a>',
'<a class="blue-font" href="$1"><img src="$1" alt=""></a>',
'<sub>$1</sub>',
'<a class="blue-font" href="http://jabber.pozitiv-r.ru/cgi-bin/mathtex.cgi?$1"><img src="http://jabber.pozitiv-r.ru/cgi-bin/mathtex.cgi?$1" alt=""></a>',
'<sup>$1</sup>'
);
// Replacing the BBcodes with corresponding HTML tags
return preg_replace($find,$replace,$text);
}
我只需要从 [tex][/tex] 标记中删除所有 </br>。我厌倦了像^<br.*?>#s 这样修改我的正则表达式,但它不起作用。
【问题讨论】:
-
你能试试我的简码库:github.com/thunderer/Shortcode 吗?它将为您节省大量时间来处理短代码。