自定义ubb代码,preg_replace()函数的一些代码

function ubb($Text) { 
  $Text=htmlspecialchars($Text); 
  $Text=ereg_replace("\r\n","
",$Text); 
  $Text=ereg_replace("\r","
",$Text); 
  $Text=nl2br($Text); 
  $Text=preg_replace("/\\t/is","  ",$Text); 
  $Text=preg_replace("/\[h1\](.+?)\[\/h1\]/is","

\\1

",$Text); 
  $Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","

\\1

",$Text); 
  $Text=preg_replace("/\[h3\](.+?)\[\/h3\]/is","

\\1

",$Text); 
  $Text=preg_replace("/\[h4\](.+?)\[\/h4\]/is","

\\1

",$Text); 
  $Text=preg_replace("/\[h5\](.+?)\[\/h5\]/is","
\\1
",$Text); 
  $Text=preg_replace("/\[h6\](.+?)\[\/h6\]/is","
\\1
",$Text); 

  $Text=preg_replace("/\[url\](http:\/\/.+?)\[\/url\]/is","\\1",$Text); 
  $Text=preg_replace("/\[url\](.+?)\[\/url\]/is","http://\\1",$Text); 
  $Text=preg_replace("/\[url=(http:\/\/.+?)\](.*)\[\/url\]/is","\\2",$Text); 
  $Text=preg_replace("/\[url=(.+?)\](.*)\[\/url\]/is","\\2",$Text); 

  $Text=preg_replace("/\[img\](.+?)\[\/img\]/is","",$Text); 
  $Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","\\2",$Text); 
  $Text=preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","\\2",$Text); 
  $Text=preg_replace("/\[sup\](.+?)\[\/sup\]/is","\\1",$Text); 
  $Text=preg_replace("/\[sub\](.+?)\[\/sub\]/is","\\1",$Text); 
  $Text=preg_replace("/\[pre\](.+?)\[\/pre\]/is","
\\1
",$Text); 
  $Text=preg_replace("/\[email\](.+?)\[\/email\]/is","\\1",$Text); 
  $Text=preg_replace("/\[i\](.+?)\[\/i\]/is","\\1",$Text); 
  $Text=preg_replace("/\[b\](.+?)\[\/b\]/is","\\1",$Text); 
  $Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","
quote:
\\1
", $Text); 
  $Text=preg_replace("/\[code\](.+?)\[\/code\]/is","
code:\\1
", $Text); 
  $Text=preg_replace("/\[sig\](.+?)\[\/sig\]/is","

--------------------------
\\1
--------------------------
", $Text); 
return $Text; 

function str($msg){
  global $admin;
  if(!$admin[html]) $msg=htmlspecialchars($msg);
  if($admin[ubb]) $msg=ubb($msg);
  $msg=nl2br($msg); #处理message
  $msg= str_replace("\n","",$msg); #处理message
  $msg= str_replace("\r","",$msg); #处理message
  return $msg;
}
function error($msg){
global $admin;
?>

中的
$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","

\\1

",$Text); 

里面的 ("/\[h2](.+?)\[\/h2]/is","

\\1

",$text)

/\[h2](.+?)\[\/h2]/is  转化成 

\\1



/\[h2](.+?)\[\/h2]/is  里面的 这些"/\(.+?)\ "之类的符号是怎么看的?是什么意思?
______________________________________________________________________________________________

\是转意,\本身是特殊符号,如果要作为普通字符就要用\来转意,就是说\\表示()也是特殊符号,所以要用\转意

你可能感兴趣的:(自定义ubb代码,preg_replace()函数的一些代码)