您的位置:首页 > 其它

随笔,发现的技巧,有用的函数

2008-07-31 10:49 267 查看
取得domobj的实际高度

domobj.clientHeight||domobj.documentElement.clientHeight;

使用socket下载一个url,默认自动尝试三次.

private function getSContent($url,$retry=0,$maxRetry=3){
$url_param = parse_url($url);
if($retry>=$maxRetry){
echo "Download $url failed!";
return false;
}else{
$fp = fsockopen($url_param['host'], 80, $errno, $errstr, 30);
if (!$fp) {
echo $k." error($retry)!/r/nTry again after 15 seconds./r/n";
sleep(15);
return $this->getSContent($url,$retry+1);
} else {
try{
$out = "GET ".$url_param['path'].'?'.$url_param['query']." HTTP/1.1/r/n";
$out .= "Accept: */*/r/n";
$out .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)/r/n";
$out .= "Host: ".$url_param['host']."/r/n";
$out .= "Connection: Close/r/n/r/n";

$contents = "";
//echo $out;
fwrite($fp, $out);
while (!feof($fp)) {
$contents .= fgets($fp, 128);
}
fclose($fp);
//去掉http头
$contents = substr($contents,strpos($contents,"/r/n/r/n")+4);
return $contents;
}catch(Exception $e){
echo $e->getMessage()."/r/nRead content error!/r/nTry again after 15 seconds./r/n";
sleep(15);
return $this->getSContent($url,$retry+1);
}
}
}
}

如果是linux服务器就可以做到,一下列出部分供你参考。
1. 取出系统Kernel版本:
$sys_host_name = file("/proc/sys/kernel/hostname");
$sys_ostype = file("/proc/sys/kernel/ostype");
$sys_osrelease = file("/proc/sys/kernel/osrelease");
$sys_version_time = file("/proc/sys/kernel/version");

2. 取出CPU信息
$cpu_info = file("/proc/cpuinfo");

3. 取出系统内存和交换分区的信息
$memory_info = file("/proc/meminfo");
$meminfo = explode(" ", $memory_info[1]);

4. 取出PS进程信息,以推算出CPU和MEM的使用率
exec("ps -aux", $ps_info_result);
for ($i = 0; $i < count($ps_info_result); $i++) {
list($user[$i], $pid[$i], $cpu[$i], $mem[$i], $vsz[$i], $rss[$i], $tty[$i], $stat[$i], $start[$i], $time[$i], $command[$i]) = split(" +", $ps_info_result[$i]);
//取出CPU用的总数(百分比)
$cpu_use_total = $cpu_use_total + $cpu[$i];
//取出MEM用的总数(百分比)
$mem_use_total = $mem_use_total + $mem[$i];
//取出MEM用的总数(KB)
$rss_use_total = $rss_use_total + $rss[$i];
}

javascript:支持firefox和ie的淡影淡出效果

<img id="aa" src="http://www.google.cn/images/nav_logo3.png" style="position:absolute;left:100px;top:100px;" onclick="FadeOrShow('aa',0,10);" />
<script language="javascript">
function FadeOrShow(id,start,step){
var obj=document.getElementById(id);
if(start<0||start>100){
return;
}
if(document.all){
obj.style.filter='alpha(opacity='+(start+step)+')';
}else{
obj.style['opacity']=(start+step)/100;
}
setTimeout('FadeOrShow("'+id+'",'+start+'+'+step+','+step+')',100);
}
FadeOrShow('aa',100,-20);
</script>

js拖动层:

<script>

var dragFlag = false;
var dragXOffset = dragYOffset = 0;

function drag(id)
{
var obj = $_(id);
if(arguments.length==2)
{
dragFlag = true;
dragXOffset=I(mouX)-I(obj.style.left);
dragYOffset=I(mouY)-I(obj.style.top);
d(dragXOffset+"**")
}
if(dragFlag!==false){
obj.style.left = I(mouX)-dragXOffset+"px";
obj.style.top = I(mouY)-dragYOffset+"px";
setTimeout("drag('"+obj.id+"')",100);
}
}

</script>

<body onmouseup="dragFlag=false;">

<div align="right" style="width:101%; border:0px solid #999999; height:18px; background-color:#000066; margin:0px; padding:0px" onmousedown="drag('editproperty',1)"></div>

文字不停变换颜色:

var colorAlertTimeOut = [];
function colorAlert(flag,obj)
{
if(flag){
if(arguments.length==2){
var colors = ['#ff0000','#00ff00','#0000ff'];
}else{
var colors = arguments[2];
}
if(colors.length<1){ alert('Color array is empty!');return;}
try{
if('undefined'==typeof(obj.id)){alert('Dom doesn/'t have a id!');return;}
}catch(e){alert('Dom doesn/'t have a id!!');return;}
var id=colorAlertTimeOut.length;
for(var i=0;i<colorAlertTimeOut.length;i++)
if(colorAlertTimeOut[i].obj_id==obj.id){
id=colorAlertTimeOut[i].id;break;
window.clearTimeout(colorAlertTimeOut[i].Alert);
}
if(typeof(colorAlertTimeOut[id])=='undefined')
{
colorAlertTimeOut[id] = {};
}
colorAlertTimeOut[id].id = id;
colorAlertTimeOut[id].color_id = 0;
colorAlertTimeOut[id].color = colors;
colorAlertTimeOut[id].obj_id = obj.id;
//colorAlertTimeOut[id].Alert = eval('setTimeout("")');
setTimeout("colorAlert(false,"+id+")",500);
}
else
{
document.getElementById(colorAlertTimeOut[obj].obj_id).style.color = colorAlertTimeOut[obj].color[colorAlertTimeOut[obj].color_id];
colorAlertTimeOut[obj].color_id++;
if(colorAlertTimeOut[obj].color_id==colorAlertTimeOut[obj].color.length) colorAlertTimeOut[obj].color_id=0;
colorAlertTimeOut[obj].Alert = setTimeout("colorAlert(false,"+obj+")",500);
}
}

//使用

colorAlert(true, document.getElementById('interlacedSpan'));

php检测用户名只能英文和简体中文

function getWordCharInt($str)
{
$str1 = preg_replace("/[/s_]/",'',$str);
if (strlen($str1) != strlen($str)) return false;
$list = array('{','}','gm','客服','kefu','代练');
foreach($list as $v)
if(strpos($str,$v)!==false) return false;
$str1 = preg_replace("//w/",'',$str1);

$flag=true;

for($i=0;$i<strlen($str1);$i++)
{
$ord = ord(substr($str,$i,1));
if($ord<0xa0||$ord>0xff)
{
$flag=false;
break;
}
}

return $flag;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: