将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
.=
"
"
;
str
.=
genRandomString(
25
);
str
.=
"
"
;
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
.
"
"
;
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
);
}
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
]
,
"
"
.
$m
[
0
][
$i
]
.
"
"
,
$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
)
,
"
"
,
$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
(
"
"
,
chr
(
13
)
,
$str
);
$str
=
eregi_replace
(
"
"
,
chr
(
13
)
,
$str
);
$str
=
eregi_replace
(
"
"
,
chr
(
13
)
,
$str
);
$str
=
eregi_replace
(
"
"
,
chr
(
13
)
,
$str
);
$str
=
eregi_replace
(
"
"
,
''
,
$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
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
//
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
.
"
"
;
$a
=
extend_2(
"
f1.txt
"
);
echo
"
ft.txt的扩展名为
"
.
$a
.
"
"
;
$a
=
extend_3(
"
f1.txt
"
);
echo
"
ft.txt的扩展名为
"
.
$a
.
"
"
;
本文转自[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