一个简单的php BBCode替换函数
function BBcode($texto){ $a = array( "/\[i\](.*?)\[\/i\]/is", "/\[b\](.*?)\[\/b\]/is", "/\[u\](.*?)\[\/u\]/is", "/\[img\](.*?)\[\/img\]/is", "/\[url=(.*?)\](.*?)\[\/url\]/is", "/\[size=(.*?)\](.*?)\[\/size\]/is", ); $b = array( "<i>$1</i>", "<b>$1</b>", "<u>$1</u>", "<img src=\"$1\" />", "<a href=\"$1\" target=\"_blank\">$2</a>", '<font size=$1>$2</font>', ); $texto = preg_replace($a, $b, $texto); $texto = nl2br($texto); return $texto; } if(isset($_GET['txt'])) { echo "Has introducido: ".bbcode($_GET['txt']); }