php ubb转换成html,html转换成ubb代码
function htmlToUBB($str)
{
$str = preg_replace("/<img[^>]+src="([^"]+)"[^>]*>/i","[img]$1[/img]",$str);
$str = preg_replace("/<embed[^>]+src="([^"]+)"[^>]*></embed>/i","[video]$1[/video]",$str);
return $str;
}
function UBB($str)
{
$auto_arr = array(
"/(?<=[^]a-z0-9-="'\/])((https?|ftp|mms|rtsp)://)([a-z0-9/-_+=.~!%@?#%&;:$\│]+)/i",
"/(?<=[^]a-z0-9/-_.~?=:.])([_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4}))/i",
"/[img](.+?)[/img]/is",
"/[video](.+?)[/video]/is"
);
$auto_url = array(
'<a href="\1\3" target="_blank">\1\3</a>',
'<a href="mailto:\0">\0</a>',
'<a href="\1" rel="Pic" class="thickbox" onfocus="this.blur()"><img class="userimg" src="\1" onError="this.src='./images/img_error.gif'" /></a>',
'<embed src="\1" quality="high" width="480" height="400" align="middle" wmode="Opaque" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>'
);
$str = preg_replace($auto_arr,$auto_url," ".$str);
$str = nl2br($str);
return $str;
}