本帖最后由 sky94132003 于 2014-10-08 01:28:06 编辑 网上一直没找到合适的bbcode解析类
我用BBCODE保存资料就是不想用户用HTML.....
<br><br><?php<br />class BBCode { <br /> public function __construct(){}<br /> private function showBBcodes($text) {<br /> // BBcode array<br /> $find = array(<br /> '~\[b\](.*?)\[/b\]~s',<br /> '~\[i\](.*?)\[/i\]~s',<br /> '~\[u\](.*?)\[/u\]~s',<br /> '~\[quote\](.*?)\[/quote\]~s',<br /> '~\[table\](.*?)\[/table\]~s',<br /> '~\[tr\](.*?)\[/tr\]~s',<br /> '~\[td\](.*?)\[/td\]~s',<br /> '~\[justify\](.*?)\[/justify\]~s',<br /> '~\[center\](.*?)\[/center\]~s',<br /> '~\[right\](.*?)\[/right\]~s',<br /> '~\[left\](.*?)\[/left\]~s',<br /> '~\[size=(.*?)\](.*?)\[/size\]~s',<br /> '~\[color=(.*?)\](.*?)\[/color\]~s',<br /> '~\[font=(.*?)\](.*?)\[/font\]~s',<br /> '~\[url=((?:ftp|https?)://.*?)\](.*?)\[/url\]~s',<br /> '~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s',<br /> '/\[img=(\d+)x(\d+)\](.*?)\[\/img\]/is',<br /> '~\[youtube\](.*?)\[/youtube\]~s',<br /> );<br /><br /> // HTML tags to replace BBcode<br /> $replace = array(<br /> '<b>$1</b>',<br> '<i>$1</i>',<br> '<span style="text-decoration:underline;">$1</span>',<br> '<pre class="brush:php;toolbar:false">$1</'.'pre>',<br> '<table>$1</table>',<br> '<tr>$1</tr>',<br> '<td>$1</td>',<br> '<div align="justify">$1</div>',<br> '<div align="center">$1</div>',<br> '<div align="right">$1</div>',<br> '<div align="left">$1</div>',<br> '<span class="h$1">$2</span>',<br> '<span style="color:$1;">$2</span>',<br> '< ;span style="font:$1;">$2</span>',<br> '<a href="$1" target="_blank" rel="nofollow">$2</a> ',<br> '<img src="$1" alt=""/>',<br> '<img width="$1" height="$2" src="$3" alt="" / >',<br> '<iframe width="560" height="315" src="http://www.youtube.com/embed/$1?wmode=opaque" data-youtube-id="$1 " frameborder="0" allowfullscreen=""></iframe>'<br> );<br> return nl2br(preg_replace($find,$replace,$text));<br> }<br><br> // 表情转义<br> private function parseSmiley($text){<br> // Smiley to image<div class="clear"></div>
ログイン後にコピー