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

2015年11月23日 星期一

Debian設定lighttpd + PHP

version info:
lighttpd: 1.4.35-4
OS: Debian GNU/Linux 8.2 (jessie)
PHP: 5.6.13

首先,假設已經安裝好PHP,

step 1:

安裝「lighttpd」和「php5-cgi」:
sudo apt-get install lighttpd php5-cgi

step 2:

enable fastcgi:
sudo lighty-enable-mod fastcgi 
sudo lighty-enable-mod fastcgi-php

step 3:

啟動lighttpd service並載入fastcgi:
sudo /etc/init.d/lighttpd enable
sudo /etc/init.d/lighttpd start
sudo /etc/init.d/lighttpd reload
Debian的lighttpd設定檔放在:
/etc/lighttpd/lighttpd.conf
參考資料:
Lighttpd+PHP
其他資源:
Arch Linuxwiki

2014年4月5日 星期六

php:isset(), null, empty(), is_null(), ===null, == null的差別

如果

$a = null;

isset($a)會傳回False

is_null($a)會傳回Ture

$a === null 會傳回True

$a == null 會傳回True

empty($a)會傳回True

----------------------------------------

$a = ture;

isset($a)會傳回True

is_null($a)會傳回False

$a === null 會傳回False

$a == null 會傳回False

empty($a)會傳回False

----------------------------------------

$a = false;


isset($a)會傳回True

is_null($a)會傳回False

$a === null 會傳回False

$a == null 會傳回True

empty($a)會傳回True

----------------------------------------

$a = 0;

isset($a)會傳回True

is_null($a)會傳回False

$a === null 會傳回False

$a == null 會傳回True

empty($a)會傳回True

----------------------------------------

$a = 1;

isset($a)會傳回True

is_null($a)會傳回False

$a === null 會傳回False

$a == null 會傳回False

empty($a)會傳回False

----------------------------------------

$a = \0;

isset($a)會傳回True

is_null($a)會傳回False

$a === null 會傳回False

$a == null 會傳回False

empty($a)會傳回False

----------------------------------------

$a 沒有被設定


isset($a)會傳回True

is_null($a)會傳回False

$a === null 會傳回False

$a == null 會傳回False

empty($a)會傳回False

----------------------------------------

$a = "";


isset($a)會傳回True

is_null($a)會傳回False

$a === null 會傳回False

$a == null 會傳回True

empty($a)會傳回True

----------------------------------------

$a = [];

isset($a)會傳回True

is_null($a)會傳回False

$a === null 會傳回False

$a == null 會傳回True

empty($a)會傳回True

----------------------------------------

圖表:













參考資料:

http://stackoverflow.com/questions/8236354/php-is-null-or-empty

2014年3月9日 星期日

php顯示錯誤訊息

可以透過函式:error_reporting()和ini_set()來完成,

用法如下:

------------------------------------------------

ini_set('display_errors', '1');

error_reporting(E_ALL);

------------------------------------------------

第一行為設定php的設定檔,

把「display_errors」這個選項設定為開啟(1)。

第二行是回報錯誤訊息的種類。

其中,error_reporting()的參數「E_ALL」表示顯示所有錯誤訊息,

其他種類的錯誤訊息可以參考:

 http://www.php.net/manual/en/errorfunc.constants.php

參考資料:

ini_set():

http://www.php.net/manual/en/function.ini-set.php

error_reporing():

http://php.net/manual/en/function.error-reporting.php

2014年1月27日 星期一

php的time()、date()、strtotime()、mktime()初步認識

int time(void):

表示從Unix紀元(1970/01/01 00:00:00)開始到現在的秒數。

傳回值為:int。





string date(string $format[, int $timestamp]):

格式化本地的時間或日期。

第一個參數($format)是格式化字串,詳細請參考:

http://tw2.php.net/manual/en/function.date.php

第二個參數為時間戳($timestamp),預設是time(),可省略。

傳回值為:string。如果參數錯誤,則回傳false。





int strtotime(string $time [, int $now = time() ]):

將英文文字轉換成時間戳(timestamp)。

第一個參數是一個英文字串,php官網範例如下:

<?php
    echo strtotime("now"), "\n";
    echo strtotime("10 September 2000"), "\n";
    echo strtotime("+1 day"), "\n";
    echo strtotime("+1 week"), "\n";
    echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
    echo strtotime("next Thursday"), "\n";
    echo strtotime("last Monday"), "\n";

?>

第二個參數恕時間戳(timestamp),預設是time(),可省略。

傳回值是:int。如果參數錯誤,則回傳false(php 5.1版之前傳回 -1)。






int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] ):

取得一個日期的Unix時間戳。

第一個參數:小時數。

第二個參數:分鐘數。

第三個參數:秒數。

第四個參數:月份數。

第五個參數:天數。

第六個參數:年數。

第七個參數:當值為1時,表示為夏令時間(Daylight saving time)。0則為非。

(php 5.1.0 以後的版本已取消第七個參數)

參數可以從右向左省略,或者說由後向前省略。

EX:

mktime(0, 0, 0, 2); //省略了天數和年數(還有夏令時間)。

傳回值:int。如果參數錯誤,則回傳false(php 5.1版之前傳回 -1)。

2013年12月8日 星期日

php剝去HTML、XML、php的tag

剛剛在思考如何在HTML tag裡取出想要的字串

翻了書發現有個好用的函式:

strip_tags();

EX:

$html_tag = '<a href="xxxxxxx">目標字串</a>';

$html_tag = strip_tags($html_tag);

echo $html_tag;
//在此會輸出:目標字串

2013年5月8日 星期三

在ubuntu中安裝apache server + php + mysql

安裝apache server:
sudo apt-get install apache2

安裝php:
sudo apt-get install php5

安裝mysql-server
sudo apt-get install mysql-server

安裝mysql for apache server:
sudo apt-get install libapache2-mod-auth-mysql
sudo apt-get install php5-mysql

安裝phpmyadmin(選擇安裝):
sudo apt-get install phpmyadmin

2013年4月28日 星期日

php的箭頭符號(減號+大於)

php的「->」用來引用某個class中的函式或變數,
或者是說調用某個class中的函式或變數。

example:

class a
{
    function  b()
    {
        echo 'hello';
    }
}

$c = new a;
$c -> b();

output: hello


參考資料:http://a22710518.pixnet.net/blog/post/28763791