顯示具有 PHP 標籤的文章。 顯示所有文章
顯示具有 PHP 標籤的文章。 顯示所有文章

2011-12-28

[PHP] number_format()

php 提供了一個 function,讓我們可以輕鬆的格式化數字

number_format

string number_format ( float $number [, int $decimals = 0 ] )
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

可以運用這個 function,
決定你的浮點數小數點後要輸出幾位($decimals),

或是,
調整你輸出的數字格式所要使用的小數點字元($dec_point),跟千位數的分隔字元($thousands_sep)

當然,不想用其中一個符號時,放個空字串('')也是可以的


Reference:
PHP: number_format

2011-11-16

Magical Methods in PHP Class

Named starting with __ as magical

__construct()
will be called on each newly-created object

__destruct()
will be called there are no other references to a particular object in any order during the shutdown sequence.

__isset()
is triggered by calling isset() or empty() on inaccessible properties.

__unset()
is invoked when unset() is used on inaccessible properties.

__set()
is run when writing data to inaccessible properties.

__get()
is utilized for reading data from inaccessible properties.

__call()
is triggered when invoking inaccessible methods in an object context.

__callStatic()
is triggered when invoking inaccessible methods in a static context.

__sleep()
serialize() checks __sleep().
executed prior to any serialization.

__wakeup()
unserialize() checks __wakeup().
this function can reconstruct any resources that the object may have.

__toString()
when it is treated like a string. must return a string

__invoke()
call an object as a function.

__set_state()
be called for classes exported by var_export()

__clone()
Once the cloning is complete,
if a __clone() method is defined,
then the newly created object's __clone() method will be called

Reference:

http://php.net/manual/en/language.oop5.magic.php 石頭閒語 - http://blog.roodo.com/rocksaying/archives/10796767.html
石頭閒語 - http://blog.roodo.com/rocksaying/archives/2683180.html

[PHP] Equal vs. Identical

Equal: ==
Identical: ===
兩個都是用來進行比較運算的 "Comparison Operators"
有什麼不一樣呢?

如果是要比較不同的資料型態時,
使用 "Equal" 時,會先轉換成相同的資料型態,再進行比較
使用 "Identical" 時,不會轉換資料型態


Reference:
http://blog.roodo.com/rocksaying/archives/2565180.html
http://www.php.net/manual/en/language.operators.comparison.php
http://www.php.net/manual/en/types.comparisons.php

2011-05-30

在 ubuntu natty 上安裝 LAMP server

好像沒什麼特別好介紹的,就分別裝上 Apache, Mysql, php 就完成了

安裝 mysql:


# apt-get install mysql-server
安裝過程中要設定 mysql 的 root password
更重要的是要把密碼記住

安裝 apache2:

# apt-get install apache2
安裝好 apache2 後,就可以連到 http://localhost/ 看看是否正常運作,
有跑起來的話,畫面上會顯示 "It works!"

安裝 php:


# apt-get install php5 php5-mysql libapache2-mod-php5

下列套件將會被【移除】:
apache2-mpm-worker

裝 php 時,會把 apache2-mpm-worker 移除,換成 apache2-mpm-prefork

安裝 phpmyadmin:

# apt-get install phpmyadmin
安裝過程會要求設定 phpmyadmin:
選擇 http server 類型,這個就是選擇我們這裡裝的 apache2 了
設定phpmyadmin 使用者密碼

phpmyadmin 裝好之後,可以連到 http://localhost/phpmyadmin/ 可以看到 phpmyadmin 的登入畫面

現在,你成功的架設了 LAMP Server,可以開始你的 PHP 之路了

Book.Study.Nyo - 在debian squeeze 上裝 LAMP

2010-12-01

[PHP] The DateTime Class

Doctrine 2 裡記錄時間都是用 PHP 的 DateTime Class
所以小研究一下

In PHP 5.2+

新增一個當前時間的 DateTime Class
$date = new DateTime("now");
ps. string "now" 可以不用打,預設就是 "now"

跟據 format 回傳 DateTime Class 的時間
echo $date->format('Y-m-d H:i:s');

參考資料:
http://www.php.net/manual/en/class.datetime.php

2010-11-17

關於自動轉址

html的寫法

<html>
  <head>
  <meta http-equiv="Refresh" content="0;URL=http://nyo-sutdybook.blogspot.com/">
  </head>
</html>
content裡的0是指幾秒後自動轉址,URL是要轉過去的網址

<html>
  <body onload="window.open('http://nyo-sutdybook.blogspot.com/','_top')">
  </body>
</html>
另一個寫法


PHP的寫法
<?php
header('Location: http://nyo-sutdybook.blogspot.com/');
?>

javascript的寫法
<script>
document.location.href="http://nyo-sutdybook.blogspot.com/";
</script>

2010-11-07

在debian squeeze 上裝 LAMP

LAMP 就是 Linux, Apache, MySQL, PHP 的簡稱,也是常見的 Web Server 組合。

安裝過程很簡單,幾個步驟就完成了~

以下介紹安裝部份!:

安裝 MySQL:
# apt-get install mysql-server mysql-client
安裝 MySQL 的過程中會要求使用者設定資料庫的 root 密碼,
請把密碼記好,否則以後忘記就麻煩了。

安裝 Apache2:
# apt-get install apache2 apache2-doc

安裝PHP:
# apt-get install php5 php5-mysql libapache2-mod-php5
apache2 預設的 mpm(multi-processing module) 是 apache2-mpm-worker,
但是裝 php5 時,會出現一個  apache2-mpm-prefork 跟它衝突,這時候兩者選一就可以,
從網路上許多的比較下似乎是 apache2-mpm-prefork 相容性及穩定性較佳,所以我裝 prefork 的 module

安裝 phpmyadmin:
phpmyadmin 這套工具,讓你可以從 web 去操作 MySQL 滿方便的~
# apt-get install phpmyadmin
安裝過程中,會需要使用者:設定對應的 www server、輸入 MySQL 的 root 密碼、設定 phpmyadmin 的使用者密碼

現在你可以用瀏覽器連到 http://localhost/ 看看裝好的 apache2 是否正常運作了~
連到 http://localhost/phpmyadmin/ 可以看到 phpmyadmin 的登入畫面