2011-05-04

php 將數字補零 使用str_pad

http://tw2.php.net/str_pad
string str_pad ( string $input , int $pad_length [, string $pad_string = " " [, int $pad_type = STR_PAD_RIGHT ]] )


<?php
$input 
"Alien";
echo 
str_pad($input10);                      // produces "Alien     "echo str_pad($input10"-="STR_PAD_LEFT);  // produces "-=-=-Alien"echo str_pad($input10"_"STR_PAD_BOTH);   // produces "__Alien___"echo str_pad($input"___");               // produces "Alien_"?>

2011-05-03

js實現判斷來源

js實現判斷當前網址的來路如果不是指定的來路就跳轉到指定頁面

<script type="text/javascript"> 
if(self!=top){top.location=self.location;} 
var ref=document.referrer; 
var domains=new Array("jb51.net/","jb51.cn/","jb51.com.cn/"); 
var refpass=false; 
for(i=0;i<=domains.length;i++){if(ref.indexOf(domains[i])>0){refpass=true;break;}} 
if(ref==""){refpass=true} 
if(!refpass){window.location.href='http://www.jb51.net';} 
</script>