常用PHP函数收集
来源:互联网 发布:穿越最后的幸存者知临 编辑:程序博客网 时间:2024/05/22 04:09
将IP最后一位替换为星号:eregi_replace('/((?:/d+/.){3})/d+/',"//1*",$ip)
生成随机字符串
< ?php
function genRandomString(len)
{
chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
"3", "4", "5", "6", "7", "8", "9"
);
charsLen = count(chars) - 1;
shuffle(chars); // 将数组打乱
output = "";
for (i=0; i<len; i++)
{
output .= chars[mt_rand(0, charsLen)];
}
return output;
}
str = genRandomString(25);
str .= "<br />";
str .= genRandomString(25);
str .= "<br />";
str .= genRandomString(25);
echo str;
?>
<?php
/* Generate Password
* Length : 8
*/
str = "0123456789abcdefghijklmnopqrstuvwxyz"; // 输出字符集
n = 8; // 输出串长度
len = strlen(str)-1;
for(j=0 ; j<200 ; j++){
for(i=0 ; i<n; i++){
s .= str[rand(0,len)];
}
echo s . "<br/>";
s = "";
}
?>
<?
function SnRndCode($length)
{
$possible = '0123456789'.
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$str = '';
while(strlen($str) < $length)
{
$str .= substr($possible, (rand() % strlen($possible)), 1);
}
return($str);
}
?>
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
function genRandomString(len)
{
chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
"3", "4", "5", "6", "7", "8", "9"
);
charsLen = count(chars) - 1;
shuffle(chars); // 将数组打乱
output = "";
for (i=0; i<len; i++)
{
output .= chars[mt_rand(0, charsLen)];
}
return output;
}
str = genRandomString(25);
str .= "<br />";
str .= genRandomString(25);
str .= "<br />";
str .= genRandomString(25);
echo str;
?>
<?php
/* Generate Password
* Length : 8
*/
str = "0123456789abcdefghijklmnopqrstuvwxyz"; // 输出字符集
n = 8; // 输出串长度
len = strlen(str)-1;
for(j=0 ; j<200 ; j++){
for(i=0 ; i<n; i++){
s .= str[rand(0,len)];
}
echo s . "<br/>";
s = "";
}
?>
<?
function SnRndCode($length)
{
$possible = '0123456789'.
'abcdefghijklmnopqrstuvwxyz'.
'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$str = '';
while(strlen($str) < $length)
{
$str .= substr($possible, (rand() % strlen($possible)), 1);
}
return($str);
}
?>
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
function utf_substr($str,$len)
{
for($i=0;$i<$len;$i++)
{
$temp_str=substr($str,0,1);
if(ord($temp_str) > 127){
$i++;
if($i<$len) {
$new_str[]=substr($str,0,3);
$str=substr($str,3);
}
}
else {
$new_str[]=substr($str,0,1);
$str=substr($str,1);
}
}
return join($new_str);
}
{
for($i=0;$i<$len;$i++)
{
$temp_str=substr($str,0,1);
if(ord($temp_str) > 127){
$i++;
if($i<$len) {
$new_str[]=substr($str,0,3);
$str=substr($str,3);
}
}
else {
$new_str[]=substr($str,0,1);
$str=substr($str,1);
}
}
return join($new_str);
}
function HilightKeyword($str,$strkey) {
$ks = explode(" ",$strkey);
if(strpos($strkey,",")){
$ks = explode(",",$strkey);
}
foreach($ks as $k){
$k = trim($k);
if($k=="") continue;
if(ord($k[0])>0x80 && strlen($k)<3) continue;
preg_match_all('/'.$k.'/i',$str,$m);
for($i=0;$i<count($m[0]);$i++) {
$str = eregi_replace($m[0][$i],"<span style='color:#FF0000;background:#FFFF99'>".$m[0][$i]."</span>",$str);
}
}
return $str;
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
$ks = explode(" ",$strkey);
if(strpos($strkey,",")){
$ks = explode(",",$strkey);
}
foreach($ks as $k){
$k = trim($k);
if($k=="") continue;
if(ord($k[0])>0x80 && strlen($k)<3) continue;
preg_match_all('/'.$k.'/i',$str,$m);
for($i=0;$i<count($m[0]);$i++) {
$str = eregi_replace($m[0][$i],"<span style='color:#FF0000;background:#FFFF99'>".$m[0][$i]."</span>",$str);
}
}
return $str;
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
function outHTML($str) {
if(!empty($str)) {
//$str = str_replace("&", "&",$str);
$str = eregi_replace("<", "<",$str);
$str = eregi_replace(">", ">",$str);
$str = eregi_replace(chr(34), """,$str);
$str = eregi_replace(chr(13), "<br>",$str);
}
return $str;
}
function inHTML($str) {
if(!empty($str)) {
//$str = str_replace("&", "&",$str);
$str = eregi_replace("<", "<",$str);
$str = eregi_replace(">", ">",$str);
$str = eregi_replace(""",chr(34),$str);
$str = eregi_replace("<br>",chr(13),$str);
$str = eregi_replace("<br />",chr(13),$str);
$str = eregi_replace("<br/>",chr(13),$str);
$str = eregi_replace("<p>",chr(13),$str);
$str = eregi_replace("</p>",'',$str);
}
return $str;
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
if(!empty($str)) {
//$str = str_replace("&", "&",$str);
$str = eregi_replace("<", "<",$str);
$str = eregi_replace(">", ">",$str);
$str = eregi_replace(chr(34), """,$str);
$str = eregi_replace(chr(13), "<br>",$str);
}
return $str;
}
function inHTML($str) {
if(!empty($str)) {
//$str = str_replace("&", "&",$str);
$str = eregi_replace("<", "<",$str);
$str = eregi_replace(">", ">",$str);
$str = eregi_replace(""",chr(34),$str);
$str = eregi_replace("<br>",chr(13),$str);
$str = eregi_replace("<br />",chr(13),$str);
$str = eregi_replace("<br/>",chr(13),$str);
$str = eregi_replace("<p>",chr(13),$str);
$str = eregi_replace("</p>",'',$str);
}
return $str;
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
function geturl()
...{
if(!empty($_SERVER['REQUEST_URI']))...{
$scriptName = $_SERVER['REQUEST_URI'];
$nowurl = $scriptName;
}
else
...{
$scriptName = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']=='')
$nowurl = $scriptName;
else
$nowurl = $scriptName.'?'.$_SERVER['QUERY_STRING'];
}
return $nowurl;
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
...{
if(!empty($_SERVER['REQUEST_URI']))...{
$scriptName = $_SERVER['REQUEST_URI'];
$nowurl = $scriptName;
}
else
...{
$scriptName = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']=='')
$nowurl = $scriptName;
else
$nowurl = $scriptName.'?'.$_SERVER['QUERY_STRING'];
}
return $nowurl;
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
function fliterstring($str,$stype)
{
if($stype == 'i') {
if(!is_numeric($str)) {
$str = false;
}
else {
$str = $str;
}
}
else {
if (!get_magic_quotes_gpc()){
$str = addslashes($str);
}
else {
$str = $str;
}
}
return $str;
}
function outputstring($str) {
if (!get_magic_quotes_gpc()){
$str = stripslashes($str);
}
else {
$str = $str;
}
return $str;
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
{
if($stype == 'i') {
if(!is_numeric($str)) {
$str = false;
}
else {
$str = $str;
}
}
else {
if (!get_magic_quotes_gpc()){
$str = addslashes($str);
}
else {
$str = $str;
}
}
return $str;
}
function outputstring($str) {
if (!get_magic_quotes_gpc()){
$str = stripslashes($str);
}
else {
$str = $str;
}
return $str;
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
//PHP获文件扩展名三法
//方法一:
function extend_1($file_name){
$retval="";
$pt=strrpos($file_name, ".");
if ($pt) $retval=substr($file_name, $pt+1, strlen($file_name) - $pt);
return ($retval);
}
//方法二
function extend_2($file_name)
{
$extend = pathinfo($file_name);
$extend = strtolower($extend["extension"]);
return $extend;
}
//方法三
function extend_3($file_name)
{
$extend =explode("." , $file_name);
$va=count($extend)-1;
return $extend[$va];
}
$a=extend_1("f1.txt");
echo "ft.txt的扩展名为".$a."<br>";
$a=extend_2("f1.txt");
echo "ft.txt的扩展名为".$a."<br>";
$a=extend_3("f1.txt");
echo "ft.txt的扩展名为".$a."<br>";
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
//方法一:
function extend_1($file_name){
$retval="";
$pt=strrpos($file_name, ".");
if ($pt) $retval=substr($file_name, $pt+1, strlen($file_name) - $pt);
return ($retval);
}
//方法二
function extend_2($file_name)
{
$extend = pathinfo($file_name);
$extend = strtolower($extend["extension"]);
return $extend;
}
//方法三
function extend_3($file_name)
{
$extend =explode("." , $file_name);
$va=count($extend)-1;
return $extend[$va];
}
$a=extend_1("f1.txt");
echo "ft.txt的扩展名为".$a."<br>";
$a=extend_2("f1.txt");
echo "ft.txt的扩展名为".$a."<br>";
$a=extend_3("f1.txt");
echo "ft.txt的扩展名为".$a."<br>";
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
function IsAllowUserIP($iplist, $userip)
{
if (empty($iplist) or empty($userip)) {
return true;
}
$iplist = str_replace(".",".",implode("|",$iplist));
$iplist = preg_replace("/*+/","d+",$iplist);
$patten = "/(".$iplist.")/";
if (preg_match($patten,$userip)) {
return false;
}
return true;
}
$iplist = array('222.169.156.34','127.0.0.2');
$userip = '127.0.0.1';
if(!IsAllowUserIP($iplist,$userip)){
echo '你的IP被封';
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
{
if (empty($iplist) or empty($userip)) {
return true;
}
$iplist = str_replace(".",".",implode("|",$iplist));
$iplist = preg_replace("/*+/","d+",$iplist);
$patten = "/(".$iplist.")/";
if (preg_match($patten,$userip)) {
return false;
}
return true;
}
$iplist = array('222.169.156.34','127.0.0.2');
$userip = '127.0.0.1';
if(!IsAllowUserIP($iplist,$userip)){
echo '你的IP被封';
}
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=451
- 常用PHP函数收集
- php 常用函数收集
- PHP常用函数收集
- PHP常用函数(收集)
- 收藏PHP常用函数收集
- PHP常用函数(数组) 收集
- PHP常用字符串函数收集(60个)
- php常用函数收集并附解释说明
- php常用函数收集并附解释说明
- php常用函数收集并附解释说明
- 整理: php常用函数收集并附解释说明
- 数据库常用函数收集
- 常用js函数收集
- 常用js函数收集
- 常用js函数收集
- VC常用函数收集
- 常用函数收集
- java常用函数收集
- 不能远程连接的问题
- 在C#中使用COM+实现事务控制
- 计量检定与计量校准证书的区别
- 保护SQL Server数据库的十个步骤
- 用SQL Server系统函数进行代码存档
- 常用PHP函数收集
- 将 MS SQL Server 2005 SP2 整合到安装文件中
- 改进SQL Server安全系统
- EssentialC++笔记1
- SQL Server管理常用的SQL和T-SQL
- 「JavaScript」梅花雪日历控件3.0-直接复制代码保存为html格式即可运行
- SQL Server管理常用的SQL和T-SQL
- 在Sql server 如何得到汉字的声母
- SQL Server的用户及权限