PHP实现HTML代码转UBB标签

添加时间:12-11-06 所属分类:PHP工具与代码
  [code]//$text = str_replace("article.shtml'","",$text);
$text = str_replace("/\r/g","",$text);
$text = str_replace("/on(load|click|dbclick|mouseover|mousedown|mouseup)=[^]+/ig","",$text);
$text = str_replace("/<script[^>]*?>([\w\W]*?)<\/script>/ig","",$text);
$text = str_replace("/<a[^>]+href=([^]+)[^>]*>(.*?)<\/a>/ig","[url=$1]$2[/url]",$text);
$text = str_replace("/<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>/ig","[color=$1]$2[/color]",$text);

$text = preg_replace("/\<img[^>]+src=\"([^\"]+)\"[^>]*\>/i","[img]$1[/img]\n",$text);
$text = preg_replace("/\<font(.*?)face=\"([^ >]+)\"(.*?)\>(.*?)<\/font>/i","<font$1$3>[face=$2]$4[/face]</font>",$text);
$text = preg_replace("/\<font(.*?)size=\"([^ >]+)\"(.*?)\>(.*?)<\/font>/i","[size=$2]$4",$text);
$text = preg_replace("/\<DIV[^>]+ALIGN=\"([^\"]+)\"[^>]*\>(.*?)<\/DIV\>/i","[align=$1]$2",$text);
$text = preg_replace("/\<([\/]?)em\>/i","[$1I]",$text);

$text = str_replace("/<([\/]?)b>/ig","[$1b]",$text);
$text = str_replace("/<([\/]?)strong>/ig","[$1b]",$text);
$text = str_replace("/<([\/]?)u>/ig","[$1u]",$text);
$text = str_replace("/<([\/]?)i>/ig","[$1i]",$text);
$text = str_replace("/&nbsp;/g"," ",$text);
$text = str_replace("/&/g","&",$text);
$text = str_replace("/&lt;/g","<",$text);
$text = str_replace("/&gt;/g",">",$text);
$text = str_replace("/<br>/ig","\n",$text);
$text = str_replace("<br />","\n",$text);
$text = str_replace("<P>","",$text);
$text = str_replace("</P>","",$text);
$text = str_replace("/<[^>]*?>/g","",$text);
$text = str_replace("/\[url=([^\]]+)\]\n(\[img\]\1\[\/img\])\n\[\/url\]/g","$2",$text);
$text = str_replace("/\n+/g","\n",$text);

$text = preg_replace( "@<script(.*?)</script>@is", "", $text );
$text = preg_replace( "@<iframe(.*?)</iframe>@is", "", $text );
$text = preg_replace( "@<style(.*?)</style>@is", "", $text );
$text = preg_replace( "@<(.*?)>@is", "", $text );[/code]

前篇:php截取指定字符之间内容的类与实例(含转码... 后篇:UBB标签转html代码的PHP函数
发表我的评论


推荐文章   济南15处免费避暑胜地   安徽29岁偏瘫教师回课堂:感谢母亲,想...   盲女心医:16年免费为2000人做心理援助   漫画《老两口》把日子记在漫画里   他们是青春中国最美的样子!
随机文章   如何优化Mysql千万级快速分页,limit优化...   PHP 5.3.6 正式发布   用PHP生成html静态页面   php读取mysql数据库内容   PHP 时间函数date() 在国外服务器上的8...
广告

其他推荐

因为本站所有内容均转载自其它媒体,本意为公众提供免费服务,但并不代表本网赞同其观点,也不能对其真实性验证负责,如稿件版权单位或个人不想在本网发布,请与我联系,本人会立即将其撤除,谢谢.联系方式:atseashawk@163.com QQ:99289555