php公用函数列表[正则]
程序员文章站
2023-04-07 13:57:00
复制代码 代码如下:
<?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
/*********************************************************************
* 公用函数列表
* 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 sprintf()函数用例解析