//seal類別
class seal {
//屬性
public $name;
public $shape;
public $diameter;
public $length;
//建構子
function __construct($name,$shape,$diameter,$length) {
$this->name=$name;
$this->shape=$shape;
$this->diameter=$diameter;
$this->length=$length;
}
public function stamp()
{
echo "(印)".$this->name."\n";
}
}
header("Contet-type:text/plain;charset=big5");
//建立實體
$obj=new seal("高島","圓柱",10,60);
//屬性
echo"私的印章的形狀是「".$obj->shape."」\n";
//方法
$obj->stamp();
2008年1月16日 星期三
物件
列出已被定義函數、變數
header("Content-Type:text/plain; charset=big5");
if(function_exists("mb_send_mail")){
echo "mb_send_mail函式已定義";
}else{
echo "mb_seind_mail函式沒定義";
}
print_r(get_defined_functions());/*列出已被定義的函數 */
print_r(get_defined_vars());/*列出已定義的變數 */
2008年1月6日 星期日
array_map(PHP函式)
說明
傳入參數:參數1是使用者自定的函式(callback function)的名稱,參數2到n是陣列型態的參數。
基本說明:依照使用者自定的函式,對陣列的元素組做處理。
結果:
Example#2 array_map() - using more arrays
結果
array array_map (mix callback , array $arr1 [, array $... ] )
傳入參數:參數1是使用者自定的函式(callback function)的名稱,參數2到n是陣列型態的參數。
基本說明:依照使用者自定的函式,對陣列的元素組做處理。
function cube($n){
return($n * $n * $n);
}
$a = array(1, 2, 3, 4, 5);
$b = array_map("cube", $a);
print_r($b);
結果:
Array
(
[0] => 1
[1] => 8
[2] => 27
[3] => 64
[4] => 125
)
Example#2 array_map() - using more arrays
function show_Spanish($n, $m)
{
return("The number $n is called $m in Spanish");
}
function map_Spanish($n, $m)
{
return(array($n => $m));
}
$a = array(1, 2, 3, 4, 5);
$b = array("uno", "dos", "tres", "cuatro", "cinco");
$c = array_map("show_Spanish", $a, $b);
print_r($c);
$d = array_map("map_Spanish", $a , $b);
print_r($d);
結果
// printout of $c
Array
(
[0] => The number 1 is called uno in Spanish
[1] => The number 2 is called dos in Spanish
[2] => The number 3 is called tres in Spanish
[3] => The number 4 is called cuatro in Spanish
[4] => The number 5 is called cinco in Spanish
)
// printout of $d
Array
(
[0] => Array
(
[1] => uno
)
[1] => Array
(
[2] => dos
)
[2] => Array
(
[3] => tres
)
[3] => Array
(
[4] => cuatro
)
[4] => Array
(
[5] => cinco
)
)
簡易資料驗證(javascript)
<HTML>
<HEAD>
<TITLE>簡易資料驗證</TITLE>
<script language="javascript">
function myFunction(){
try{
if(document.myForm.ID.value !="test"){
throw "idError"
}else if(document.myForm.psw.value !="test"){
throw"pswError"
}else{
alert("身份驗證通過")
}
}catch(e){
if(e=="idError")alert("帳號資料不符")
if(e=="pswError")alert("密碼資料不符")
}
}
</script>
</HEAD>
<BODY >
<center>
進入會員專區前,請先登入:<BR>
<form name="myForm">
帳號:<input type="text" name="ID" size="10"><br>
密碼:<input type="password" name="psw" size="10"><br>
<input type="button" value="身份驗證" onClick="myFunction()">
</form>
</BODY>
</HTML>
訂閱:
文章 (Atom)