Home > Article > Backend Development > A ubbcode function, very fast._PHP tutorial
I saw someone publish
before, but it is slow and very long
Here is a
function ubb($str) {
$color=Array('red',' blue','green');
$str=eregi_replace('[url]([a-zA-Z0-9@:%_.~#-?&]+)[/url]','< ;a href=http://\1>\1',$str);//url
$str=eregi_replace('[url=http://([a-zA-Z0- 9@:%_.~#-?&]+)](.+)[/url]','\2',$str);
$str=eregi_replace('[url=([a-zA-Z0-9@:%_.~#-?&]+)](.+)[/url]','\2',$str);
$str=eregi_replace('[img]([a-zA-Z0-9@:%_.~# -?&]+)[/img]','\1',$str);//img
$str=eregi_replace('[ h([1-6])](.+)[/h[1-6]]','
$str=eregi_replace('[email]([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2 ,3})[/email]','\1',$str);//email
$str=eregi_replace('[email=([ _.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})](.+)[/email]' ,'\2',$str);
$str=eregi_replace('[b](.+)[/b]','',$str);
$str=eregi_replace('[i](.+)[/i]','\1',$str );
$str=eregi_replace('[size=(.+)](.+)[/size]','\2',$str);
$str=eregi_replace('[color=(.+)](.+)[/color]','\2',$str);
$str=eregi_replace('[sub](.+)[/sub]','\1',$str);//下裱
$str=eregi_replace(' [sup](.+)[/sup]','\1',$str);//Superscript
for($i=0;$i<=count( $color);$i++)$str=eregi_replace('['.$color[$i].'](.+)[/'.$color[$i].']','\1',$str);
$str=preg_replace("/[quote](.+?)[/quote]/is", "quote:
", $str);
\1
$str=preg_replace("/[code](.+?)[/code]/is","code:< /font>
", $str);
\1
$str= preg_replace("/[sig](.+?)[/sig]/is","
--------------------------
\1
---------- ---------------
return $str;
}