当前位置: 首页 - 标签 - UBB
显示模式: 普通 | 列表

PHP实现HTML转UBB

/**
* 解析HTML为UBB函数
*
* @param string $str 要解析的字符串
* @return string
*/
function parse($str)
{
$str = str_replace("\n",'',$str);
$str = preg_replace("/\<A[^>]+HREF=\"([^\"]+)\"[^>]*\>(.*?)<\/a\>/i","[url=$1]$2[/url]",$str);
$str = preg_replace("/\<font(.*?)color=\"#([^ >]+)\"(.*?)\>(.*?)<\/font>/i","<font$1$3>[color=$2]$4[/color]</font>",$str);
$str = preg_replace("/\<font(.*?)face=\"([^ >]+)\"(.*?)\>(.*?)<\/font>/i","<font$1$3>[face=$2]$4[/face]</font>",$str);
$str = preg_replace("/\<font(.*?)size=\"([^ >]+)\"(.*?)\>(.*?)<\/font>/i","[size=$2]$4[/size]",$str);
$str = preg_replace("/\<img[^>]+src=\"([^\"]+)\"[^>]*\>/i","[img]$1[/img]",$str);
$str = preg_replace("/\<DIV[^>]+ALIGN=\"([^\"]+)\"[^>]*\>(.*?)<\/DIV\>/i","[align=$1]$2[/align]",$str);
$str = preg_replace("/\<([\/]?)u\>/i","[$1u]",$str);
$str = preg_replace("/\<([\/]?)em\>/i","[$1I]",$str);
$str = preg_replace("/\<([\/]?)strong\>/i","[$1b]",$str);
$str = preg_replace("/\<([\/]?)b(.*?)\>/i","[$1b]",$str);


阅读全文...

分类: PHP | Web Developing  引用: 0  评论: 0  点击: 11