php公用函数列表[正则]

所属分类: 网络编程 / PHP编程 阅读数: 1603
收藏 0 赞 0 分享
复制代码 代码如下:

<?php
/*********************************************************************
* 公用函数列表
* ubb,getip,GoIn,goback,IsInt,InString
* OurHome:http://iwind.org
* http://10.13.31.90/~coldwind

* */
/////////////////ubb支持代码函数////////////////////////////
function ubb($Text) { 
  $Text=trim($Text);
  $Text=htmlspecialchars($Text);  
  $Text=ereg_replace("\n","<br>",$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("/\[center\](.+?)\[\/center\]/is","<center>\\1</center>",$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='1' face='Courier New'>quote:</font><hr>\\1<hr></blockquote>", $Text); 
  $Text=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote><font size='1' face='Times New Roman'>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; 
}

////////////////取得浏览者的ip地址/////////////////////////////
function getip() { 
   $IP=getenv('REMOTE_ADDR'); 
   $IP_ = getenv('HTTP_X_FORWARDED_FOR'); 
   if (($IP_ != "") && ($IP_ != "unknown")) $IP=$IP_; 
   return $IP; 

function goback($num,$saying){
echo"<table align=\"center\"><tr><td><a href=\"javascript:history.go(-1)\">$saying</a>";
}
///////////////////判断字符串中是否含有array中的某一值/////////////////
function InString($array,$string){
  while(list(,$value)=each($array)){
   if(eregi($value,$string)){
   return true;
   exit;
  }
  }
}
////////////////////链接到某一页面///////////////////////////////////////
function GoIn($addr,$saying){
echo"<table align=\"center\"><tr><td><a href=\"$addr\">$saying</a></td></tr></table>";
}
////////////////////JS返回//////////////////////////////////////////////
function IsInt($string){
  if(ereg("^[0-9]{0,}$",$string)){
  return true;
  }
   else {
  return false;
  }
}
?>
更多精彩内容其他人还在看

两种php去除二维数组的重复项方法

这篇文章主要介绍了两种php去除二维数组的重复项方法,大家可以进行比较看哪一种更适合自己,需要的朋友可以参考下
收藏 0 赞 0 分享

php实现分页功能的3种方法第1/3页

这篇文章主要介绍了php实现分页功能的3种方法,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

php对二维数组进行相关操作(排序、转换、去空白等)

这篇文章主要介绍了php对二维数组进行相关操作,包括php对二维数组排序、转换、去空白,以及去重复值等,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

php实现网站留言板功能

这篇文章主要介绍了php实现网站留言板功能,主要仿照了畅言留言板和网易跟帖样式进行制作,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

PHP实现HTML页面静态化的方法

这篇文章主要介绍了PHP实现HTML页面静态化的方法,分享了静态处理的方法,静态处理后的优势,并提供了多种静态的方法,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

php对文件夹进行相关操作(遍历、计算大小)

这篇文章主要介绍了php对文件夹进行相关操作,包括遍历并打印指定目录下所有文件和计算文件大小去空白,以及去重复值等,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

非常全面的php日期时间运算汇总

这篇文章主要整理了关于php日期时间运算相关内容,涉及知识点较为全面,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

php根据用户语言跳转相应网页

这篇文章主要介绍了php根据用户语言跳转相应网页的方法,主要区分国内国外,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

双冒号 ::在PHP中的使用情况

前几天在百度知道里面看到有人问PHP中双冒号::的用法,当时给他的回答比较简洁因为手机打字不大方便!今天突然想起来,所以在这里总结一下我遇到的双冒号::在PHP中使用的情况
收藏 0 赞 0 分享

PHP explode()函数的几个应用和implode()函数有什么区别

这篇文章主要介绍了PHP explode()函数的几个应用和implode()函数有什么区别,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多