欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php Ubb代码编辑器函数代码

程序员文章站 2022-06-03 10:25:30
复制代码 代码如下:
复制代码 代码如下:

<?php
/*
php ubb代码编辑器
*/
function get_ubb($ubb){
$ubb=preg_replace("/([b])(.*)([/b])/","<b>\2</b>" ,$ubb);//替换b粗体字
$ubb=preg_replace("/([i])(.*)([/i])/","<i>\2</i>" ,$ubb);
$ubb=preg_replace("/([u])(.*)([/u])/","<u>\2</u>" ,$ubb);
$ubb=preg_replace("/([lef])(.*)([/lef])/","<div align=left>\2</div>" ,$ubb);
$ubb=preg_replace("/([mid ])(.*)([/mid ])/","<div align=center>\2</div>" ,$ubb);
$ubb=preg_replace("/([rig])(.*)([/rig])/","<div align=right>\2</div>" ,$ubb);
$ubb=preg_replace("/([link])(.*)([/link])/","<a href=\2>\2</a>",$ubb);
$ubb=preg_replace("/([email])(.*)([/email])/","<a href=mailto:\2>\2</a>",$ubb);
$ubb=preg_replace("/([image])(.*)([/image])/","<img src=\2>",$ubb);
$ubb=preg_replace("/([flash])(.*)([/flash])/","<object codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 width=400 height=400><param name=movie value="\2"><param name=quality value=high><embed src="\2" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash' type='application/x-shockwave-flash' width=400 height=400 ></embed></object>" ,$ubb);
$ubb=preg_replace("/([music])(.*)([/music])/","<embed src=\2 autostart=false loop=3>" ,$ubb);
$ubb=preg_replace("/([photo name=)([0-9]*)(])/","<img src=ubb_img/biaoqing/\2.gif >" ,$ubb);
$ubb=preg_replace("/([font=)(.{1,10})(])(.*)([/font])/","<div style=font:\2>\4</div>" ,$ubb);
$ubb=preg_replace("/([font-size=)([0-9]*)(])(.*)([/font-size])/","<div style=font-size:\2px>\4</div>" ,$ubb);
$ubb=preg_replace("/([font-color=)(.{1,10})(])(.*)([/font-color])/","<div style=color:\2>\4</div>" ,$ubb);
//$ubb=preg_replace("/([])(.*)([/])/","" ,$ubb);
return $ubb;
}
$str=get_ubb($_post['cont']);
$str="<div style=font:宋体>[font=黑体]asdasd</div><div style=font:georgia>asdasdas[/font]</div>";
echo get_ubb($str);
?>