判断升降
if($_REQUEST["order"]==$name && ($_REQUEST["order"]<>"price_sum" && $_REQUEST["order"]<>"price_current" && $_REQUEST["order"]<>"storage_loss"))
{
if($_REQUEST["type"]=="asc")
{
$outstr.=" <a href='http://admin.ebol.com.cn/ERP/storage.php?order=".$name."&type=desc&compare=".$_GET["compare"]."&age=".$_GET["age"]."&temp=".$temp."'><strong>".$param_name."</strong><img src='images/s_asc.png' title='升' border='0'></a>";
}
else
{
$outstr.=" <a href='http://admin.ebol.com.cn/ERP/storage.php?order=".$name."&type=asc&compare=".$_GET["compare"]."&age=".$_GET["age"]."&temp=".$temp."'><strong>".$param_name."</strong><img src='images/s_desc.png' title='降' border='0'></a>";
}
}
else
$outstr.=" <a href='http://admin.ebol.com.cn/ERP/storage.php?order=".$name."&type=asc&compare=".$_GET["compare"]."&age=".$_GET["age"]."&temp=".$temp."'><strong>".$param_name."</strong></a>";
///
计算库龄
$input = mktime(substr($input_time,11,2),substr($input_time,14,2),substr($input_time,17,2),substr($input_time,5,2),substr($input_time,8,2),substr($input_time,0,4));
$date = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
$storage_age= $date-$input;库龄
$storage_age= date("z",$storage_age);
//
$_server[],$_get[]
/
"http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
/
文件处理
$cur_static_index_file_name="static/list/list_".(int)$categoryid."_".(int)$subcategoryid.".html";
$can_cache=(!$page && !ereg("keyword=",$_SERVER['QUERY_STRING']) && !ereg("manufacturerid=",$_SERVER['QUERY_STRING']) && !ereg("price_range=",$_SERVER['QUERY_STRING']) && !ereg("order=",$_SERVER['QUERY_STRING']) && !ereg("Param_",$_SERVER['QUERY_STRING']));//判断为第一页并且未提交搜索
if($can_cache==1)
{
if(($refresh!=1)&&file_exists($cur_static_index_file_name)&&(time()-filectime($cur_static_index_file_name))<60*30*1)//file://用refresh可以手动更新静态文件,60*10*1表示时间为10分钟
{
$date = date("Y-m-d H:i:s",filectime($cur_static_index_file_name));
echo "<!--";
echo "cache file ".basename($cur_static_index_file_name)." build at ".$date;
echo "-->/r";
echo "<!--";
echo "query string [".$_SERVER['QUERY_STRING']."]";
echo "-->/r";
echo "<script>document.location='$cur_static_index_file_name';</script>";
include($cur_static_index_file_name);
exit();
}
$is_write=1;
ob_start();
}
$the_content = ob_get_contents();
if(!is_dir("static"))
mkdir("static",0775);
if(!is_dir("static/list "))
mkdir("static/list",0777);
$fp = fopen($cur_static_index_file_name, "w");
flock($fp, 2);
fputs($fp, $the_content);
flock($fp, 3);
fclose($fp);
ob_end_flush();
}
/* 截取一定长度的完整的中文字符 */
///
function cnsubstr($str,$strlen=10) {
for($i=0;$i<$strlen;$i++)
if(ord(substr($str,$i,1))>0xa0) $j++;
if($j%2!=0) $strlen++;
$str=substr($str,0,$strlen);
return $str;
}
//
设置cookie和读取
/
setcookie("zol_userid", $User, 0,"/",".ebol.com.cn");
/
正则表达
/
preg_match()
preg_match_all()
ereg()返回true or false
匹配双字节字符(包括汉字在内):[^/x00-/xff]
echo HTMLSpecialChars($ad_content);
/
SQL语句
/
select count(*) as lixin from pro_pv_2006_11 where subcategoryid='3' and ip<>'' and productid<>''
select pro_pv_2006.id from pro_pv_2006_11 left join lixin on pro_pv_2006_11.id=lixin.id;
javascript
/
window.prompt("请输入修改后的名称",name);
document.location = "http://www.ebol.com.cn";
///
php读取mssql日期出现中文字符的解决方法
第一个方法:php文档开头定义ini_set(”mssql.datetimeconvert”,”0″);
第二个方法:修改php.ini,找到;mssql.datetimeconvert = On ,去掉前面的分号,修改on为off,重启apache即可
ajax 处理问题
if(xmlHttp.responseText.search(re) != '-1'){
//alert('22');
document.getElementById("txtUserName").innerHTML = xmlHttp.responseText;
document.getElementById("txtPassWord").innerHTML = '';
}else if(xmlHttp.responseText == 'b'){
}else {
document.getElementById("txtUserName").innerHTML = '';
document.getElementById("txtPassWord").innerHTML = xmlHttp.responseText;
}
javascript
onclick = "javascript:if(event.keyCode==13){
ajaxFunction('login');
}"
///
100 => "HTTP/1.1 100 Continue",
101 => "HTTP/1.1 101 Switching Protocols",
200 => "HTTP/1.1 200 OK",
201 => "HTTP/1.1 201 Created",
202 => "HTTP/1.1 202 Accepted",
203 => "HTTP/1.1 203 Non-Authoritative Information",
204 => "HTTP/1.1 204 No Content",
205 => "HTTP/1.1 205 Reset Content",
206 => "HTTP/1.1 206 Partial Content",
300 => "HTTP/1.1 300 Multiple Choices",
301 => "HTTP/1.1 301 Moved Permanently",
302 => "HTTP/1.1 302 Found",
303 => "HTTP/1.1 303 See Other",
304 => "HTTP/1.1 304 Not Modified",
305 => "HTTP/1.1 305 Use Proxy",
307 => "HTTP/1.1 307 Temporary Redirect",
400 => "HTTP/1.1 400 Bad Request",
401 => "HTTP/1.1 401 Unauthorized",
402 => "HTTP/1.1 402 Payment Required",
403 => "HTTP/1.1 403 Forbidden",
404 => "HTTP/1.1 404 Not Found",
405 => "HTTP/1.1 405 Method Not Allowed",
406 => "HTTP/1.1 406 Not Acceptable",
407 => "HTTP/1.1 407 Proxy Authentication Required",
408 => "HTTP/1.1 408 Request Time-out",
409 => "HTTP/1.1 409 Conflict",
410 => "HTTP/1.1 410 Gone",
411 => "HTTP/1.1 411 Length Required",
412 => "HTTP/1.1 412 Precondition Failed",
413 => "HTTP/1.1 413 Request Entity Too Large",
414 => "HTTP/1.1 414 Request-URI Too Large",
415 => "HTTP/1.1 415 Unsupported Media Type",
416 => "HTTP/1.1 416 Requested range not satisfiable",
417 => "HTTP/1.1 417 Expectation Failed",
500 => "HTTP/1.1 500 Internal Server Error",
501 => "HTTP/1.1 501 Not Implemented",
502 => "HTTP/1.1 502 Bad Gateway",
503 => "HTTP/1.1 503 Service Unavailable",
504 => "HTTP/1.1 504 Gateway Time-out"
特殊字符
//
<a>&#;</a>169
©
==比较句柄
equals比较赋值
///
//
document.form1.showtoCity.options[document.form1.showtoCity.length] = new Option(subcat[i][0], subcat[i][1]);
//
返回顶部,获得焦点
///
<a name="top" id="top"></a>
<a href="#top"></a>
window.document.form1.name.focus();
///
js 匹配
var Pat1=/^/d+$/; //匹配数字
var Pat2=/^([^/x00-/xff]|/d)+$/; //匹配所有双字节长度的字符和数字组成的字符串
var Pat3=/^[^/x00-/xff]+$/; //匹配所有双字节长度的字符组成的字符串
if(!Pat1.test(aaa)) {alert('必须数字!');return false;}
if(!Pat2.test(sss)) {alert('必须汉字和数字!');return false;}
if(!Pat3.test(ddd)) {alert('必须汉字!');return false;}
原帖子地址
http://community.csdn.net/Expert/topic/5075/5075191.xml?temp=.8922235
以下是例子:
利用正则表达式限制网页表单里的文本框输入内容:
用正则表达式限制只能输入中文:οnkeyup="value=value.replace(/[^/u4E00-/u9FA5]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/u4E00-/u9FA5]/g,''))"
1.用正则表达式限制只能输入全角字符: οnkeyup="value=value.replace(/[^/uFF00-/uFFFF]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/uFF00-/uFFFF]/g,''))"
2.用正则表达式限制只能输入数字:οnkeyup="value=value.replace(/[^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"
3.用正则表达式限制只能输入数字和英文:οnkeyup="value=value.replace(/[/W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"
4.计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)
String.prototype.len=function(){return this.replace([^/x00-/xff]/g,"aa").length;}
5.javascript中没有像vbscript那样的trim函数,我们就可以利用这个表达式来实现,如下:
String.prototype.trim = function()
{
return this.replace(/(^/s*)|(/s*$)/g, "");
}
利用正则表达式分解和转换IP地址:
6.下面是利用正则表达式匹配IP地址,并将IP地址转换成对应数值的Javascript程序:
function IP2V(ip)
{
re=/(/d+)/.(/d+)/.(/d+)/.(/d+)/g //匹配IP地址的正则表达式
if(re.test(ip))
{
return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
}
else
{
throw new Error("不是一个正确的IP地址!")
}
}
不过上面的程序如果不用正则表达式,而直接用split函数来分解可能更简单,程序如下:
var ip="10.100.20.168"
ip=ip.split(".")
alert("IP值是:"+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))
正则表达式用于字符串处理、表单验证等场合,实用高效。现将一些常用的表达式收集于此,以备不时之需。
匹配中文字符的正则表达式: [/u4e00-/u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了
匹配双字节字符(包括汉字在内):[^/x00-/xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)
匹配空白行的正则表达式:/n/s*/r
评注:可以用来删除空白行
匹配HTML标记的正则表达式:<(/S*?)[^>]*>.*?<//1>|<.*? />
评注:网上流传的版本太糟糕,上面这个也仅仅能匹配部分,对于复杂的嵌套标记依旧无能为力
匹配首尾空白字符的正则表达式:^/s*|/s*$
评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式
匹配Email地址的正则表达式:/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*
评注:表单验证时很实用
匹配网址URL的正则表达式:[a-zA-z]+://[^/s]*
评注:网上流传的版本功能很有限,上面这个基本可以满足需求
匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
评注:表单验证时很实用
匹配国内电话号码:/d{3}-/d{8}|/d{4}-/d{7}
评注:匹配形式如 0511-4405222 或 021-87888822
匹配腾讯QQ号:[1-9][0-9]{4,}
评注:腾讯QQ号从10000开始
匹配中国邮政编码:[1-9]/d{5}(?!/d)
评注:中国邮政编码为6位数字
匹配身份证:/d{15}|/d{18}
评注:中国的身份证为15位或18位
匹配ip地址:/d+/./d+/./d+/./d+
评注:提取ip地址时有用
匹配特定数字:
^[1-9]/d*$ //匹配正整数
^-[1-9]/d*$ //匹配负整数
^-?[1-9]/d*$ //匹配整数
^[1-9]/d*|0$ //匹配非负整数(正整数 + 0)
^-[1-9]/d*|0$ //匹配非正整数(负整数 + 0)
^[1-9]/d*/./d*|0/./d*[1-9]/d*$ //匹配正浮点数
^-([1-9]/d*/./d*|0/./d*[1-9]/d*)$ //匹配负浮点数
^-?([1-9]/d*/./d*|0/./d*[1-9]/d*|0?/.0+|0)$ //匹配浮点数
^[1-9]/d*/./d*|0/./d*[1-9]/d*|0?/.0+|0$ //匹配非负浮点数(正浮点数 + 0)
^(-([1-9]/d*/./d*|0/./d*[1-9]/d*))|0?/.0+|0$ //匹配非正浮点数(负浮点数 + 0)
评注:处理大量数据时有用,具体应用时注意修正
匹配特定字符串:
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串
^/w+$ //匹配由数字、26个英文字母或者下划线组成的字符串
评注:最基本也是最常用的一些表达式
匹配中文字符的正则表达式: [/u4e00-/u9fa5]
匹配双字节字符(包括汉字在内):[^/x00-/xff]
匹配空行的正则表达式:/n[/s| ]*/r
匹配HTML标记的正则表达式:/<(.*)>.*<///1>|<(.*) //>/
匹配首尾空格的正则表达式:(^/s*)|(/s*$)
匹配Email地址的正则表达式:/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*
匹配网址URL的正则表达式:http://([/w-]+/.)+[/w-]+(/[/w- ./?%&=]*)?
^/d+$ //匹配非负整数(正整数 + 0)
^[0-9]*[1-9][0-9]*$ //匹配正整数
^((-/d+)|(0+))$ //匹配非正整数(负整数 + 0)
^-[0-9]*[1-9][0-9]*$ //匹配负整数
^-?/d+$ //匹配整数
^/d+(/./d+)?$ //匹配非负浮点数(正浮点数 + 0)
^(([0-9]+/.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*/.[0-9]+)|([0-9]*[1-9][0-9]*))$ //匹配正浮点数
^((-/d+(/./d+)?)|(0+(/.0+)?))$ //匹配非正浮点数(负浮点数 + 0)
^(-(([0-9]+/.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*/.[0-9]+)|([0-9]*[1-9][0-9]*)))$ //匹配负浮点数
^(-?/d+)(/./d+)?$ //匹配浮点数
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串
^/w+$ //匹配由数字、26个英文字母或者下划线组成的字符串
^[/w-]+(/.[/w-]+)*@[/w-]+(/.[/w-]+)+$
Email : /^/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/,
Phone : /^((/(/d{2,3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}(/-/d{1,4})?$/,
Mobile : /^((/(/d{2,3}/))|(/d{3}/-))?13/d{9}$/,
Url : /^http:[A-Za-z0-9]+/.[A-Za-z0-9]+[//=/?%/-&_~`@[/]/':+!]*([^<>/"/"])*$/,
Currency : /^/d+(/./d+)?$/,
Number : /^/d+$/,
Zip : /^[1-9]/d{5}$/,
QQ : /^[1-9]/d{4,8}$/,
Integer : /^[-/+]?/d+$/,
Double : /^[-/+]?/d+(/./d+)?$/,
English : /^[A-Za-z]+$/,
Chinese : /^[/u0391-/uFFE5]+$/,
Username : /^[a-z]/w{3,}$/i,
UnSafe : /^(([A-Z]*|[a-z]*|/d*|[-_/~!@#/$%/^&/*/./(/)/[/]/{/}<>/?/'/"]*)|.{0,5})$|/s/
}
几种跳转方法
window.history.go(0)
window.location.reload()
window.location.href=location.href
window.location.assign(location.href)
document.execCommand('Refresh')
window.navigate(location.href)
window.navigate("#pos");
window.location.replace(location.href)
window.open('自身的文件','_self')
-------------
location.reload(flag)
flag =true 不从缓存读取
=false 从缓存读取
//
访客ip
$_SERVER['REMOTE_ADDR'];
$_SERVER['HTTP_X_FORWARDED_FOR'];
报错
//
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
///
///
function abc() {
if(connection_timeout()) {
//脚本超时处理部分
echo '<script language="javascript" type="text/JavaScript">
document.location ="regerror.htm";
</script>';
}
}
register_shutdown_function('abc');
///
<a href="#" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http: //www.windstudio.net');">设为首页</a>
添加到收藏夹:
<a href="javascript:window.external.AddFavorite('http://www.windstudio.net', '有风的日子·带给你一阵清新的设计风')">加入收藏</a>
//
window.setTimeout()一次
window.setInterval()无数次
window.clearTimeout()
上传图片
<form id="form1" method="post" enctype="multipart/form-data" name="nameform1">
//
$str=str_replace(" ","",$str);
$str=str_replace(chr(32),"",$str)
上面的方法只能处理英文空格的情况.
下面的方法可以处理中文只的空格,不过有个情况是如果页面指定了编码的话会出现乱码
$str=str_replace(chr(32),"",$str);
$str=str_replace(chr(161),"",$str);
对于页面为UTF-8是,中文空格提交后变成了chr(227),原应为chr(161)
//
if($_REQUEST["order"]==$name && ($_REQUEST["order"]<>"price_sum" && $_REQUEST["order"]<>"price_current" && $_REQUEST["order"]<>"storage_loss"))
{
if($_REQUEST["type"]=="asc")
{
$outstr.=" <a href='http://admin.ebol.com.cn/ERP/storage.php?order=".$name."&type=desc&compare=".$_GET["compare"]."&age=".$_GET["age"]."&temp=".$temp."'><strong>".$param_name."</strong><img src='images/s_asc.png' title='升' border='0'></a>";
}
else
{
$outstr.=" <a href='http://admin.ebol.com.cn/ERP/storage.php?order=".$name."&type=asc&compare=".$_GET["compare"]."&age=".$_GET["age"]."&temp=".$temp."'><strong>".$param_name."</strong><img src='images/s_desc.png' title='降' border='0'></a>";
}
}
else
$outstr.=" <a href='http://admin.ebol.com.cn/ERP/storage.php?order=".$name."&type=asc&compare=".$_GET["compare"]."&age=".$_GET["age"]."&temp=".$temp."'><strong>".$param_name."</strong></a>";
///
计算库龄
$input = mktime(substr($input_time,11,2),substr($input_time,14,2),substr($input_time,17,2),substr($input_time,5,2),substr($input_time,8,2),substr($input_time,0,4));
$date = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
$storage_age= $date-$input;库龄
$storage_age= date("z",$storage_age);
//
$_server[],$_get[]
/
"http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
/
文件处理
$cur_static_index_file_name="static/list/list_".(int)$categoryid."_".(int)$subcategoryid.".html";
$can_cache=(!$page && !ereg("keyword=",$_SERVER['QUERY_STRING']) && !ereg("manufacturerid=",$_SERVER['QUERY_STRING']) && !ereg("price_range=",$_SERVER['QUERY_STRING']) && !ereg("order=",$_SERVER['QUERY_STRING']) && !ereg("Param_",$_SERVER['QUERY_STRING']));//判断为第一页并且未提交搜索
if($can_cache==1)
{
if(($refresh!=1)&&file_exists($cur_static_index_file_name)&&(time()-filectime($cur_static_index_file_name))<60*30*1)//file://用refresh可以手动更新静态文件,60*10*1表示时间为10分钟
{
$date = date("Y-m-d H:i:s",filectime($cur_static_index_file_name));
echo "<!--";
echo "cache file ".basename($cur_static_index_file_name)." build at ".$date;
echo "-->/r";
echo "<!--";
echo "query string [".$_SERVER['QUERY_STRING']."]";
echo "-->/r";
echo "<script>document.location='$cur_static_index_file_name';</script>";
include($cur_static_index_file_name);
exit();
}
$is_write=1;
ob_start();
}
$the_content = ob_get_contents();
if(!is_dir("static"))
mkdir("static",0775);
if(!is_dir("static/list "))
mkdir("static/list",0777);
$fp = fopen($cur_static_index_file_name, "w");
flock($fp, 2);
fputs($fp, $the_content);
flock($fp, 3);
fclose($fp);
ob_end_flush();
}
/* 截取一定长度的完整的中文字符 */
///
function cnsubstr($str,$strlen=10) {
for($i=0;$i<$strlen;$i++)
if(ord(substr($str,$i,1))>0xa0) $j++;
if($j%2!=0) $strlen++;
$str=substr($str,0,$strlen);
return $str;
}
//
设置cookie和读取
/
setcookie("zol_userid", $User, 0,"/",".ebol.com.cn");
/
正则表达
/
preg_match()
preg_match_all()
ereg()返回true or false
匹配双字节字符(包括汉字在内):[^/x00-/xff]
echo HTMLSpecialChars($ad_content);
/
SQL语句
/
select count(*) as lixin from pro_pv_2006_11 where subcategoryid='3' and ip<>'' and productid<>''
select pro_pv_2006.id from pro_pv_2006_11 left join lixin on pro_pv_2006_11.id=lixin.id;
javascript
/
window.prompt("请输入修改后的名称",name);
document.location = "http://www.ebol.com.cn";
///
php读取mssql日期出现中文字符的解决方法
第一个方法:php文档开头定义ini_set(”mssql.datetimeconvert”,”0″);
第二个方法:修改php.ini,找到;mssql.datetimeconvert = On ,去掉前面的分号,修改on为off,重启apache即可
ajax 处理问题
if(xmlHttp.responseText.search(re) != '-1'){
//alert('22');
document.getElementById("txtUserName").innerHTML = xmlHttp.responseText;
document.getElementById("txtPassWord").innerHTML = '';
}else if(xmlHttp.responseText == 'b'){
}else {
document.getElementById("txtUserName").innerHTML = '';
document.getElementById("txtPassWord").innerHTML = xmlHttp.responseText;
}
javascript
onclick = "javascript:if(event.keyCode==13){
ajaxFunction('login');
}"
///
100 => "HTTP/1.1 100 Continue",
101 => "HTTP/1.1 101 Switching Protocols",
200 => "HTTP/1.1 200 OK",
201 => "HTTP/1.1 201 Created",
202 => "HTTP/1.1 202 Accepted",
203 => "HTTP/1.1 203 Non-Authoritative Information",
204 => "HTTP/1.1 204 No Content",
205 => "HTTP/1.1 205 Reset Content",
206 => "HTTP/1.1 206 Partial Content",
300 => "HTTP/1.1 300 Multiple Choices",
301 => "HTTP/1.1 301 Moved Permanently",
302 => "HTTP/1.1 302 Found",
303 => "HTTP/1.1 303 See Other",
304 => "HTTP/1.1 304 Not Modified",
305 => "HTTP/1.1 305 Use Proxy",
307 => "HTTP/1.1 307 Temporary Redirect",
400 => "HTTP/1.1 400 Bad Request",
401 => "HTTP/1.1 401 Unauthorized",
402 => "HTTP/1.1 402 Payment Required",
403 => "HTTP/1.1 403 Forbidden",
404 => "HTTP/1.1 404 Not Found",
405 => "HTTP/1.1 405 Method Not Allowed",
406 => "HTTP/1.1 406 Not Acceptable",
407 => "HTTP/1.1 407 Proxy Authentication Required",
408 => "HTTP/1.1 408 Request Time-out",
409 => "HTTP/1.1 409 Conflict",
410 => "HTTP/1.1 410 Gone",
411 => "HTTP/1.1 411 Length Required",
412 => "HTTP/1.1 412 Precondition Failed",
413 => "HTTP/1.1 413 Request Entity Too Large",
414 => "HTTP/1.1 414 Request-URI Too Large",
415 => "HTTP/1.1 415 Unsupported Media Type",
416 => "HTTP/1.1 416 Requested range not satisfiable",
417 => "HTTP/1.1 417 Expectation Failed",
500 => "HTTP/1.1 500 Internal Server Error",
501 => "HTTP/1.1 501 Not Implemented",
502 => "HTTP/1.1 502 Bad Gateway",
503 => "HTTP/1.1 503 Service Unavailable",
504 => "HTTP/1.1 504 Gateway Time-out"
特殊字符
//
<a>&#;</a>169
©
==比较句柄
equals比较赋值
///
//
document.form1.showtoCity.options[document.form1.showtoCity.length] = new Option(subcat[i][0], subcat[i][1]);
//
返回顶部,获得焦点
///
<a name="top" id="top"></a>
<a href="#top"></a>
window.document.form1.name.focus();
///
js 匹配
var Pat1=/^/d+$/; //匹配数字
var Pat2=/^([^/x00-/xff]|/d)+$/; //匹配所有双字节长度的字符和数字组成的字符串
var Pat3=/^[^/x00-/xff]+$/; //匹配所有双字节长度的字符组成的字符串
if(!Pat1.test(aaa)) {alert('必须数字!');return false;}
if(!Pat2.test(sss)) {alert('必须汉字和数字!');return false;}
if(!Pat3.test(ddd)) {alert('必须汉字!');return false;}
原帖子地址
http://community.csdn.net/Expert/topic/5075/5075191.xml?temp=.8922235
以下是例子:
利用正则表达式限制网页表单里的文本框输入内容:
用正则表达式限制只能输入中文:οnkeyup="value=value.replace(/[^/u4E00-/u9FA5]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/u4E00-/u9FA5]/g,''))"
1.用正则表达式限制只能输入全角字符: οnkeyup="value=value.replace(/[^/uFF00-/uFFFF]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/uFF00-/uFFFF]/g,''))"
2.用正则表达式限制只能输入数字:οnkeyup="value=value.replace(/[^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"
3.用正则表达式限制只能输入数字和英文:οnkeyup="value=value.replace(/[/W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"
4.计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)
String.prototype.len=function(){return this.replace([^/x00-/xff]/g,"aa").length;}
5.javascript中没有像vbscript那样的trim函数,我们就可以利用这个表达式来实现,如下:
String.prototype.trim = function()
{
return this.replace(/(^/s*)|(/s*$)/g, "");
}
利用正则表达式分解和转换IP地址:
6.下面是利用正则表达式匹配IP地址,并将IP地址转换成对应数值的Javascript程序:
function IP2V(ip)
{
re=/(/d+)/.(/d+)/.(/d+)/.(/d+)/g //匹配IP地址的正则表达式
if(re.test(ip))
{
return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
}
else
{
throw new Error("不是一个正确的IP地址!")
}
}
不过上面的程序如果不用正则表达式,而直接用split函数来分解可能更简单,程序如下:
var ip="10.100.20.168"
ip=ip.split(".")
alert("IP值是:"+(ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1))
正则表达式用于字符串处理、表单验证等场合,实用高效。现将一些常用的表达式收集于此,以备不时之需。
匹配中文字符的正则表达式: [/u4e00-/u9fa5]
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了
匹配双字节字符(包括汉字在内):[^/x00-/xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)
匹配空白行的正则表达式:/n/s*/r
评注:可以用来删除空白行
匹配HTML标记的正则表达式:<(/S*?)[^>]*>.*?<//1>|<.*? />
评注:网上流传的版本太糟糕,上面这个也仅仅能匹配部分,对于复杂的嵌套标记依旧无能为力
匹配首尾空白字符的正则表达式:^/s*|/s*$
评注:可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式
匹配Email地址的正则表达式:/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*
评注:表单验证时很实用
匹配网址URL的正则表达式:[a-zA-z]+://[^/s]*
评注:网上流传的版本功能很有限,上面这个基本可以满足需求
匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
评注:表单验证时很实用
匹配国内电话号码:/d{3}-/d{8}|/d{4}-/d{7}
评注:匹配形式如 0511-4405222 或 021-87888822
匹配腾讯QQ号:[1-9][0-9]{4,}
评注:腾讯QQ号从10000开始
匹配中国邮政编码:[1-9]/d{5}(?!/d)
评注:中国邮政编码为6位数字
匹配身份证:/d{15}|/d{18}
评注:中国的身份证为15位或18位
匹配ip地址:/d+/./d+/./d+/./d+
评注:提取ip地址时有用
匹配特定数字:
^[1-9]/d*$ //匹配正整数
^-[1-9]/d*$ //匹配负整数
^-?[1-9]/d*$ //匹配整数
^[1-9]/d*|0$ //匹配非负整数(正整数 + 0)
^-[1-9]/d*|0$ //匹配非正整数(负整数 + 0)
^[1-9]/d*/./d*|0/./d*[1-9]/d*$ //匹配正浮点数
^-([1-9]/d*/./d*|0/./d*[1-9]/d*)$ //匹配负浮点数
^-?([1-9]/d*/./d*|0/./d*[1-9]/d*|0?/.0+|0)$ //匹配浮点数
^[1-9]/d*/./d*|0/./d*[1-9]/d*|0?/.0+|0$ //匹配非负浮点数(正浮点数 + 0)
^(-([1-9]/d*/./d*|0/./d*[1-9]/d*))|0?/.0+|0$ //匹配非正浮点数(负浮点数 + 0)
评注:处理大量数据时有用,具体应用时注意修正
匹配特定字符串:
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串
^/w+$ //匹配由数字、26个英文字母或者下划线组成的字符串
评注:最基本也是最常用的一些表达式
匹配中文字符的正则表达式: [/u4e00-/u9fa5]
匹配双字节字符(包括汉字在内):[^/x00-/xff]
匹配空行的正则表达式:/n[/s| ]*/r
匹配HTML标记的正则表达式:/<(.*)>.*<///1>|<(.*) //>/
匹配首尾空格的正则表达式:(^/s*)|(/s*$)
匹配Email地址的正则表达式:/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*
匹配网址URL的正则表达式:http://([/w-]+/.)+[/w-]+(/[/w- ./?%&=]*)?
^/d+$ //匹配非负整数(正整数 + 0)
^[0-9]*[1-9][0-9]*$ //匹配正整数
^((-/d+)|(0+))$ //匹配非正整数(负整数 + 0)
^-[0-9]*[1-9][0-9]*$ //匹配负整数
^-?/d+$ //匹配整数
^/d+(/./d+)?$ //匹配非负浮点数(正浮点数 + 0)
^(([0-9]+/.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*/.[0-9]+)|([0-9]*[1-9][0-9]*))$ //匹配正浮点数
^((-/d+(/./d+)?)|(0+(/.0+)?))$ //匹配非正浮点数(负浮点数 + 0)
^(-(([0-9]+/.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*/.[0-9]+)|([0-9]*[1-9][0-9]*)))$ //匹配负浮点数
^(-?/d+)(/./d+)?$ //匹配浮点数
^[A-Za-z]+$ //匹配由26个英文字母组成的字符串
^[A-Z]+$ //匹配由26个英文字母的大写组成的字符串
^[a-z]+$ //匹配由26个英文字母的小写组成的字符串
^[A-Za-z0-9]+$ //匹配由数字和26个英文字母组成的字符串
^/w+$ //匹配由数字、26个英文字母或者下划线组成的字符串
^[/w-]+(/.[/w-]+)*@[/w-]+(/.[/w-]+)+$
Email : /^/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*$/,
Phone : /^((/(/d{2,3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}(/-/d{1,4})?$/,
Mobile : /^((/(/d{2,3}/))|(/d{3}/-))?13/d{9}$/,
Url : /^http:[A-Za-z0-9]+/.[A-Za-z0-9]+[//=/?%/-&_~`@[/]/':+!]*([^<>/"/"])*$/,
Currency : /^/d+(/./d+)?$/,
Number : /^/d+$/,
Zip : /^[1-9]/d{5}$/,
QQ : /^[1-9]/d{4,8}$/,
Integer : /^[-/+]?/d+$/,
Double : /^[-/+]?/d+(/./d+)?$/,
English : /^[A-Za-z]+$/,
Chinese : /^[/u0391-/uFFE5]+$/,
Username : /^[a-z]/w{3,}$/i,
UnSafe : /^(([A-Z]*|[a-z]*|/d*|[-_/~!@#/$%/^&/*/./(/)/[/]/{/}<>/?/'/"]*)|.{0,5})$|/s/
}
几种跳转方法
window.history.go(0)
window.location.reload()
window.location.href=location.href
window.location.assign(location.href)
document.execCommand('Refresh')
window.navigate(location.href)
window.navigate("#pos");
window.location.replace(location.href)
window.open('自身的文件','_self')
-------------
location.reload(flag)
flag =true 不从缓存读取
=false 从缓存读取
//
访客ip
$_SERVER['REMOTE_ADDR'];
$_SERVER['HTTP_X_FORWARDED_FOR'];
报错
//
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
///
///
function abc() {
if(connection_timeout()) {
//脚本超时处理部分
echo '<script language="javascript" type="text/JavaScript">
document.location ="regerror.htm";
</script>';
}
}
register_shutdown_function('abc');
///
<a href="#" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http: //www.windstudio.net');">设为首页</a>
添加到收藏夹:
<a href="javascript:window.external.AddFavorite('http://www.windstudio.net', '有风的日子·带给你一阵清新的设计风')">加入收藏</a>
//
window.setTimeout()一次
window.setInterval()无数次
window.clearTimeout()
上传图片
<form id="form1" method="post" enctype="multipart/form-data" name="nameform1">
//
$str=str_replace(" ","",$str);
$str=str_replace(chr(32),"",$str)
上面的方法只能处理英文空格的情况.
下面的方法可以处理中文只的空格,不过有个情况是如果页面指定了编码的话会出现乱码
$str=str_replace(chr(32),"",$str);
$str=str_replace(chr(161),"",$str);
对于页面为UTF-8是,中文空格提交后变成了chr(227),原应为chr(161)
//