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

function ubb($Text) { 

  $Text=htmlspecialchars($Text); 

  $Text=ereg_replace("\r\n","<br>",$Text); 

  $Text=ereg_replace("\r","<br>",$Text); 

  $Text=nl2br($Text); 

  $Text=preg_replace("/\\t/is","  ",$Text); 

  $Text=preg_replace("/\[h1\](.+?)\[\/h1\]/is","<h1>\\1</h1>",$Text); 

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

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

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

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

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

$Text=preg_replace("/\[url\](http:\/\/.+?)\[\/url\]/is","<a href=\\1>\\1</a>",$Text); 

  $Text=preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\"http://\\1\">http://\\1</a>",$Text); 

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

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

$Text=preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\\1>",$Text); 

  $Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$Text); 

  $Text=preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","<font size=\\1>\\2</font>",$Text); 

  $Text=preg_replace("/\[sup\](.+?)\[\/sup\]/is","<sup>\\1</sup>",$Text); 

  $Text=preg_replace("/\[sub\](.+?)\[\/sub\]/is","<sub>\\1</sub>",$Text); 

  $Text=preg_replace("/\[pre\](.+?)\[\/pre\]/is","<pre>\\1</pre>",$Text); 

  $Text=preg_replace("/\[email\](.+?)\[\/email\]/is","<a href=\\1>\\1</a>",$Text); 

  $Text=preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$Text); 

  $Text=preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$Text); 

  $Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote><font size='2' face='Courier New'>quote:</font><hr>\\1<hr></blockquote>", $Text); 

  $Text=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote><font size='2' face='Courier New'>code:</font><hr color='lightblue'><i>\\1</i><hr color='lightblue'></blockquote>", $Text); 

  $Text=preg_replace("/\[sig\](.+?)\[\/sig\]/is","<div style='text-align: left; color: darkgreen; margin-left: 5%'><br><br>--------------------------<br>\\1<br>--------------------------</div>", $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","<h2>\\1</h2>",$Text);

里面的 ("/\[h2](.+?)\[\/h2]/is","<h2>\\1</h2>",$text)

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

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

______________________________________________________________________________________________

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

时间: 2024-08-02 17:40:13

自定义ubb代码,preg_replace()函数的一些代码的相关文章

自定义ubb代码,preg_replace()函数的一些代码_正则表达式

function ubb($Text) {    $Text=htmlspecialchars($Text);    $Text=ereg_replace("\r\n","<br>",$Text);    $Text=ereg_replace("\r","<br>",$Text);    $Text=nl2br($Text);    $Text=preg_replace("/\\t/is&qu

php下过滤html代码的函数 提高程序安全性_php技巧

以下为过滤HTML代码的函数: 复制代码 代码如下: function ihtmlspecialchars($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = ihtmlspecialchars($val); } } else { $string = preg_replace('/&((#(\d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-z0-9]{

eregi_replace与preg_replace 函数代码的用法比较_正则表达式

eregi_replace ( string pattern, string replacement, string string ) preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit [, int &count]] ) 以上两个函数基本义定义我知道 但是里面样式或参数的定义我搞不懂 例如以下是UBB与YBB Code的用法 $str = eregi_replace("\\[url]ht

eregi_replace与preg_replace 函数代码的用法比较

eregi_replace ( string pattern, string replacement, string string ) preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit [, int &count]] ) 以上两个函数基本义定义我知道 但是里面样式或参数的定义我搞不懂 例如以下是UBB与YBB Code的用法 $str = eregi_replace("\\[url]ht

php preg_replace函数基础与实例代码

//preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) 主题为匹配搜索模式,替换替换 /* 要搜索的模式.它可以是一个字符串或一个字符串数组. 电子修饰符使preg_replace函数()替代治疗后,适当引用作为参数是php教程代码进行替换.提示:请确保置换构成一个有效的php代码字符串,否则php将抱怨在包含preg_replace函

php分页函数完整实例代码_php技巧

本文分享一例php分页函数完整实例代码,使用此函数实现分页效果很不错.分享给大家供大家参考. 具体功能代码如下: <?php /* * Created on 2011-07-28 * 使用方法: require_once('mypage.php'); $result=mysql_query("select * from mytable", $myconn); $total=mysql_num_rows($result); //取得信息总数 pageDivide($total,10

java 某个类的几个对象,这些对象调用类中一个函数,是各自拥有自己的函数代码还是使用同一段代码?

问题描述 1.java 某个类的几个对象,这些对象调用类中一个函数(普通的函数),是各自拥有自己的函数代码还是使用同一段代码?2.java 继承中,子类从父类得到一些普通函数,这些函数的代码,是子类自己独自拥有一份还是和父类使用同一段函数代码.3.第一次发帖,积分什么的不会搞,貌似自己也没有积分,呵呵,大家包涵! 解决方案 引用1.java 某个类的几个对象,这些对象调用类中一个函数(普通的函数),是各自拥有自己的函数代码还是使用同一段代码?这几个对象调用的当然是同一段代码了.jvm中有一个ja

printf-c语言 残缺程序(函数)的代码怎么改?

问题描述 c语言 残缺程序(函数)的代码怎么改? 描述 Cloud是个喜欢探险的程序员,在一次探险的时候,偶然发现了一些残缺的文件.这些文件上都是用c/c++写的程序代码.为了解开残缺文件的谜团,Cloud决定尽力补全这些残缺的程序代码,以便发现更多的秘密.第一份残缺文件上的代码如下,请帮助他补全程序.(打星号的地方需要补全) 程序名称:计算从1到n之间的完数个数. #include ****** ******(******) { int i,s; s=******; for(i=******;

c++-阅读别人做的mfc的源代码时应该怎样读啊。那么多代码。函数。变量。

问题描述 阅读别人做的mfc的源代码时应该怎样读啊.那么多代码.函数.变量. 阅读别人做的mfc的源代码时应该怎样读啊.那么多代码.函数.变量.期末要做一个mfc小游戏,由于比较菜就在网上下了几个人家做好的mfc小游戏,想根据人家的源码一点一点仿写..但是由于mfc基础薄弱..读源码又感觉很困难,试过直接复制人家的代码,但是一运行,就全是错误...应该怎样阅读啊..有顺序吗 解决方案 先学习下mfc写程序的基础知识,搞清楚哪些代码是向导生成的,哪些是添加进去的,每个源代码是干嘛的.这样看这种程序