如题
格式如下:
//PHP实现
function(str) //这个str是字符串类型的html代码,例如:'<div><a >开始访问</a></div>'
{
//相关逻辑处理代码
return str;
}
需求说明;小弟知道用正则表达式处理,但是鉴于小弟不太熟悉正则表达式,虽然在学习正则!
相关:我找到了一个html转换为ubb的代码:php实现的,如下
function htmltoubb($str)
{
$str = str_replace("\n",'',$str);
$str = preg_replace("/\<A[^>]+HREF=\"([^\"]+)\"[^>]*\>(.*?)<\/a\>/i","$2",$str);
$str = preg_replace("/\<font(.*?)color=\"#([^ >]+)\"(.*?)\>(.*?)<\/font>/i","<font$1$3>[color=$2]$4</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",$str);
$str = preg_replace("/\<img[^>]+src=\"([^\"]+)\"[^>]*\>/i","",$str);
$str = preg_replace("/\<DIV[^>]+ALIGN=\"([^\"]+)\"[^>]*\>(.*?)<\/DIV\>/i","[align=$1]$2",$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);
$str = preg_replace("/\<([\/]?)i\>/i","[$1i]",$str);
$str = preg_replace("/<[^>]*?>/i","",$str);
return $str;
}
但是ubb代码和dz代码还是有区别的,希望哪位大神帮忙实现一下,万分感谢!可以随时qq我:
|