当前位置: 编程技术>php
本页文章导读:
▪php下过滤HTML代码的函数
/*---------------------- 过滤HTML代码的函数 -----------------------*/ function htmlEncode($string) { $string=trim($string); $string=str_replace("&","&",$string); $string=str_replace("'","'",$string); .........
▪php字符串截取中文截取2,单字节截取模式
//中文截取2,单字节截取模式 function cn_substr($str,$slen,$startdd=0){ $restr = ""; $c = ""; $str_len = strlen($str); if($str_len < $startdd+1) return ""; if($str_len < $startdd.........
▪php获得当前的脚本网址
//获得当前的脚本网址 function GetCurUrl(){ if(!empty($_SERVER["REQUEST_URI"])){ $scriptName = $_SERVER["REQUEST_URI"]; $nowurl = $scriptName; }else{ $scriptName = $_SERV.........
[1]php下过滤HTML代码的函数
来源: 互联网 发布时间: 2013-11-30
/*----------------------
过滤HTML代码的函数
-----------------------*/
function htmlEncode($string) {
$string=trim($string);
$string=str_replace("&","&",$string);
$string=str_replace("'","'",$string);
$string=str_replace("&","&",$string);
$string=str_replace(""",""",$string);
$string=str_replace("\"",""",$string);
$string=str_replace("<","<",$string);
$string=str_replace("<","<",$string);
$string=str_replace(">",">",$string);
$string=str_replace(">",">",$string);
$string=str_replace(" "," ",$string);
$string=nl2br($string);
return $string;
}
过滤HTML代码的函数
-----------------------*/
function htmlEncode($string) {
$string=trim($string);
$string=str_replace("&","&",$string);
$string=str_replace("'","'",$string);
$string=str_replace("&","&",$string);
$string=str_replace(""",""",$string);
$string=str_replace("\"",""",$string);
$string=str_replace("<","<",$string);
$string=str_replace("<","<",$string);
$string=str_replace(">",">",$string);
$string=str_replace(">",">",$string);
$string=str_replace(" "," ",$string);
$string=nl2br($string);
return $string;
}
[2]php字符串截取中文截取2,单字节截取模式
来源: 互联网 发布时间: 2013-11-30
//中文截取2,单字节截取模式
function cn_substr($str,$slen,$startdd=0){
$restr = "";
$c = "";
$str_len = strlen($str);
if($str_len < $startdd+1) return "";
if($str_len < $startdd + $slen || $slen==0) $slen = $str_len - $startdd;
$enddd = $startdd + $slen - 1;
for($i=0;$i<$str_len;$i++)
{
if($startdd==0) $restr .= $c;
else if($i > $startdd) $restr .= $c;
if(ord($str[$i])>0x80){
if($str_len>$i+1) $c = $str[$i].$str[$i+1];
$i++;
}
else{ $c = $str[$i]; }
if($i >= $enddd){
if(strlen($restr)+strlen($c)>$slen) break;
else{ $restr .= $c; break; }
}
}
return $restr;
}
function cn_midstr($str,$start,$len){
return cn_substr($str,$slen,$startdd);
}
function cn_substr($str,$slen,$startdd=0){
$restr = "";
$c = "";
$str_len = strlen($str);
if($str_len < $startdd+1) return "";
if($str_len < $startdd + $slen || $slen==0) $slen = $str_len - $startdd;
$enddd = $startdd + $slen - 1;
for($i=0;$i<$str_len;$i++)
{
if($startdd==0) $restr .= $c;
else if($i > $startdd) $restr .= $c;
if(ord($str[$i])>0x80){
if($str_len>$i+1) $c = $str[$i].$str[$i+1];
$i++;
}
else{ $c = $str[$i]; }
if($i >= $enddd){
if(strlen($restr)+strlen($c)>$slen) break;
else{ $restr .= $c; break; }
}
}
return $restr;
}
function cn_midstr($str,$start,$len){
return cn_substr($str,$slen,$startdd);
}
[3]php获得当前的脚本网址
来源: 互联网 发布时间: 2013-11-30
//获得当前的脚本网址
function GetCurUrl(){
if(!empty($_SERVER["REQUEST_URI"])){
$scriptName = $_SERVER["REQUEST_URI"];
$nowurl = $scriptName;
}else{
$scriptName = $_SERVER["PHP_SELF"];
if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;
else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];
}
return $nowurl;
}
function GetCurUrl(){
if(!empty($_SERVER["REQUEST_URI"])){
$scriptName = $_SERVER["REQUEST_URI"];
$nowurl = $scriptName;
}else{
$scriptName = $_SERVER["PHP_SELF"];
if(empty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;
else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];
}
return $nowurl;
}
最新技术文章: