自定义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:39:59

自定义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

关于preg_replace函数的问题讲解_正则表达式

请问下那此句语句的作用.给我解释一下其中的"?","e","i","s"符号分别是什么意思,和它们起到了什么作用.还有就是除了"/eis"外还有其他什么模式了吗?      如果有相关的学习资料可以给我吗?谢谢,各位的帮助!谢谢.      $post=preg_replace("/\[html\](.+?)\[\/html\]/eis","htmlcode('\\1')&qu

UBB代码在论坛中的应用_正则表达式

一.读者指引 读者指引帮助你掌握本文的梗概.以免你看了大半才明白这编文章不适合你,给你造成视觉污染. 如果你正在用ASP写程序,或者你正在写一些诸如BBS.留言溥或表单数据检查之类的东东那就值得一看. 如果你对正则表达式已经了如指掌,那么你不必一行行的看,只要看看我写的模板,再比较一下,取其精华就行了. 如果你还是第一次接触正则表达式,那么你最好一行行的看,并逐条试验 当你熟练的掌握了正则表达式的用法,你就会发现其乐无穷. 二.正则表达式的概念 什么是UBB代码?什么是正则表达式? UBB代码是

PHP 正则表达式函数库(两套)_正则表达式

在PHP中有两套正则表达式函数库,两者功能相似,只是执行效率略有差异: 一套是由PCRE(Perl Compatible Regular Expression)库提供的.使用"preg_"为前缀命名的函数: 一套由POSIX(Portable Operating System Interface of Unix )扩展提供的(PHP默认).使用以"ereg_"为前缀命名的函数: PHP中,正则表达式有三个作用: 匹配,也常常用于从字符串中析取信息. 用新文本代替匹配

PHP preg match正则表达式函数的操作实例_正则表达式

在php中preg_match()函数是用来执行正则表达式的一个常用的函数.正则表达式几乎在所有编程语言里面都会用到,本实例介绍php中正则表达式preg_match函数的应用. preg_match() 函数用于进行正则表达式匹配,成功返回 1 ,否则返回 0 . preg_match() 匹配成功一次后就会停止匹配,如果要实现全部结果的匹配,则需使用 preg_match_all() 函数. 语法: preg_match (pattern , subject, matches) 参数 描述

js正则表达式验证URL函数代码(方便多个正则对比)_正则表达式

推荐大家收藏的一段代码,方便同时测试多个正则,查看不同的检测结果,结合chrome完美 核心代码 <script> /** * 正则表达式判断网址是否有效 */ (function(){ "use strict"; var urlDict=[ //Bad Case 'www.baidu.com', //常规网址,未带协议头的地址 'w.baidu.com', //常规网址,短子域名 'baidu.com', //常规网址,仅有主域名 '测试.com', //非常规合法网址,

asp的ubb函数(推荐)_正则表达式

复制代码 代码如下:  function unHtml(content) unHtml=content if content <> "" then unHtml=replace(unHtml,"&","&") unHtml=replace(unHtml,"<","<") unHtml=replace(unHtml,">",">

php中正则替换函数ereg_replace用法实例_正则表达式

本文实例讲述了php中正则替换函数ereg_replace用法.分享给大家供大家参考.具体如下: 下面的实例是利用php 正则替换函数 ereg_replace来把指定的字符替换成我想需要的字符实例,代码如下: 复制代码 代码如下: $num = 'www.jb51.net'; $string = "this string has four words. <br>"; $string = ereg_replace ('four', $num, $string); echo

密码强度检测函数(正则)_正则表达式

      贝因美冠军宝贝大赛专用信息平台入口 用户名或密码错误,请重新输入. 帐号/编号: 密码: 密码强度检测    申请OA帐号   打勾后表示下次自动登陆 2006贝因美冠军宝贝大赛省级晋级赛进行时 帮助文档 意见反馈   222.212.7.171