[composer](https://getcomposer.org/)是目前最多人使用的php套件管理單,
只要下一個指令,
就可以將所有套件相依性的軟體下載,
並只要require一隻autoload.php即可
不過要安裝composer有些步驟得進行,
說明一下如何安裝composer
1.下載windows版composer[下載](https://getcomposer.org/Composer-Setup.exe) 並安裝(安裝過程中,會要求指定php.exe資料夾)

2. 開始右鍵 => 系統 => 進階系統設定 => 環境變數

3. 新增變數
變數名稱: PHP_HOME
變數值: PHP路徑(範例為C:\PHP)

4. 新增變數
變數名稱: COMPOSER_HOME
變數值: C:\ProgramData\ComposerSetup

5. 修改path
在原本的path後面新增
;%PHP_HOME%;%COMPOSER_HOME%\bin;%COMPOSER_HOME%\vendor\bin
※由於已經設定%COMPOSER_HOME%所以往後利用 composer global require 套件
都會安裝至%COMPOSER_HOME%\vendor
如果套件內有執行檔則會自動安裝至%COMPOSER_HOME%\vendor\bin
所以%COMPOSER_HOME%\vendor\bin也要加入path變數之中
6. 打開command模式,直接執行composer即可

2015年4月12日 星期日
uniform server 在windows下體積小快速安裝的wamp server
在Windows裡安裝wamp server
除了常見到的[xampp](https://www.apachefriends.org/zh_tw/index.html)、[wampserver](http://www.wampserver.com/en/)之外
還有這一套『[uniform server](http://www.uniformserver.com/)』
uniform server標榜的是體積小
主程式安裝檔案也才27M
不過相對功能就比較少
安裝程式只包含了apache、php5.4、mysql
其他的phpmyadmin、mariadb等等都可以利用plugin的方式來進行安裝
至於安裝的方法,只要將[檔案](http://sourceforge.net/projects/miniserver/files/latest/download?source=files)下載後,解壓縮到任一資料夾就可以使用了
以下為安裝步驟
1. 下載檔案(只有27M)

2. 點擊兩下解壓縮

3. 進入UniServerZ資料夾

4. 點擊UniController.exe(用系統管理員身份執行才能設定開機後自動執行wamp)

5. 允許防火牆

6. 更改mysql root預設密碼,不更改可直接點選cancel(預設密碼為 root)

7. 啟動apache及mysql

8. 設定開機執行apache及mysql


9. 這樣就設定完成了
![Alt text]()
其他比較常用到的apache及php設定
1.設定apache rewrite
2.設定php curl
要更改apache及php的設得先停止apache
設定rewrite的方法


設定php curl


2013年9月24日 星期二
TimelineMax background position change
用TimelineMAX來寫動畫是一件很簡單的事情
不過在寫連續的動畫圖,卻遇到了麻煩
```javascript
var tl = new TimelineMax({repeat:-1});
tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-683px -222px'}});
tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-693px -111px'}});
tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-693px -0px'}});
tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-595px -525px'}});
tl.to($('.Scroll'),0.1,{css:{'backgroundPosition':'-517px -525px'}});
```
如果這樣寫的時候,會發現background-position在變換的時候會由A點移動到B點,
而不是原本所預想的直接換background-position
試了很久終於想到可以用delay方式來處理就行了
所以正確的程式碼如下
```javascript
var tl = new TimelineMax({repeat:-1});
tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-683px -222px'}},'+=.1');
tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-693px -111px'}},'+=.1');
tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-693px -0px'}},'+=.1');
tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-595px -525px'}},'+=.1');
tl.to($('.Scroll'),0,{css:{'backgroundPosition':'-517px -525px'}},'+=.1');
```
2013年6月26日 星期三
tinymce 4.0版外掛和主程式不同路徑怎麼解決
// 只要設定 window.tinymce.baseURL就能指定plugin的資料夾了
```javascript
window.tinymce.baseURL = '任意路徑'
```
2013年6月4日 星期二
simple_html_dom 轉 array
[simple_html_dom](http://simplehtmldom.sourceforge.net/)是一個很好用的 x(h)tml解析器
不過在使用上有些麻煩
所以就自己寫了將simple_html_dom轉array的function
xml檔案
```xml
<orderdoc>
<dochead>
<docno>999XXXyyyymmdd99</docno>
<docdate>2009-02-01</docdate>
<parentid>999</parentid>
</dochead>
<doccontent>
<order>
<eshopid>001</eshopid>
<opmode>A</opmode>
<eshoporderno>200906010001</eshoporderno>
<eshoporderdate>2009-02-01</eshoporderdate>
<servicetype>1</servicetype>
<shoppername>張小明</shoppername>
<shopperphone></shopperphone>
<shoppermobilphone></shoppermobilphone>
<shopperemail></shopperemail>
<receivername>張小明</receivername>
<receiverphone></receiverphone>
<receivermobilphone></receivermobilphone>
<receiveremail></receiveremail>
<receiveridnumber></receiveridnumber>
<orderamount>2000</orderamount>
<orderdetail>
<productid></productid>
<productname></productname>
<quantity></quantity>
<unit></unit>
<unitprice></unitprice>
</orderdetail>
<shipmentdetail>
<shipmentno>20000001</shipmentno>
<shipdate>2009-02-01</shipdate>
<returndate>2009-02-9</returndate>
<lastshipment>Y</LastShipment>
<shipmentamount>2000</shipmentamount>
<storeid>886751</storeid>
<eshoptype>04</eshoptype>
</shipmentdetail>
</lastshipment>
</returndate>
</shipdate>
</shipmentno>
</shipmentdetail>
</order>
<order>
<eshopid>001</eshopid>
<opmode>A</opmode>
<eshoporderno>200906010002</eshoporderno>
<eshoporderdate>2009-02-01</eshoporderdate>
廠商上線說明書
This Document is 7-Eleven /PIC/ Presco Confidential Page: 17
<servicetype>1</servicetype>
<shoppername>林志玲</shoppername>
<shopperphone></shopperphone>
<shoppermobilphone></shoppermobilphone>
<shopperemail></shopperemail>
<receivername>林志玲</receivername>
<receiverphone></receiverphone>
<receivermobilphone></receivermobilphone>
<receiveremail></receiveremail>
<receiveridnumber></receiveridnumber>
<orderamount>1200</orderamount>
<orderdetail>
<productid></productid>
<productname></productname>
<quantity></quantity>
<unit></unit>
<unitprice></unitprice>
</orderdetail>
<shipmentdetail>
<shipmentno>20000002</shipmentno>
<shipdate>2009-02-01</shipdate>
<returndate>2009-02-9</returndate>
<lastshipment>N</LastShipment>
<shipmentamount>800</shipmentamount>
<storeid>886750</storeid>
<eshoptype>04</eshoptype>
</shipmentdetail>
<shipmentdetail>
<shipmentno>20000003</shipmentno>
<shipdate>2009-02-01</shipdate>
<returndate>2009-02-9</returndate>
<lastshipment>Y</LastShipment>
<shipmentamount>400</shipmentamount>
<storeid>886750</storeid>
<eshoptype>04</eshoptype>
<shipmentdetail>
</lastshipment>
</returndate>
</shipdate>
</shipmentno>
</shipmentdetail>
</lastshipment>
</returndate>
</shipdate>
</shipmentno>
</shipmentdetail>
</order>
</doccontent>
</orderdoc>
```
php檔案
```php
define("DOCROOT",dirname(__FILE__)."/");
require DOCROOT."simple_html_dom.php";
function domToArray($elements)
{
$results = array();
foreach ($elements as $element)
{
if (count($element->children) > 0)
{
$results[$element->tag][] = domToArray($element->children);
}
else
{
$results[$element->tag] = $element->text();
}
}
return $results;
}
$root = file_get_html(DOCROOT."test.xml");
$order_doms = domToArray($root->find("Order"));
print_r($order_doms);
```
2013年6月2日 星期日
php 民國年日期計算
西元年轉民國年,還要再處理日期的加減
光用php的date函數或是mktime是一件很麻煩的事情
所幸php內建了DataTime這個class來協助處理這件事情
```php
// 西元年轉民國年,並取得5天後的日期
$date = new DateTime("now");
$date->modify("+5 day");
$date->modify("-1911 year")
// 由於Y為四位數,所以利用ltrim去0
echo ltrim($date->format("Y-m-d H:i:s"),"0");
// 民國年轉西元年,並取得10天前的日期
$date = new DateTime("101-01-01");
$date->modify("+5 day");
$date->modify("+1911 year")
echo $date->format("Y-m-d H:i:s");
```
2013年2月5日 星期二
tempnam修改
有時候在寫程式的時候會用到暫存檔
一般我們可能都是用PHP內建的tempnam來建立暫存檔
但有時候用到某些library時,
會去認檔案的副檔名,但內建的tempnam所產出的暫存檔副檔名皆為 .tmp
所以就自己另外寫了一個程式來替代暫存檔的產生
```php
class File
{
public static function tempnam($dir = NULL,$suffix = "tmp"){
$name = strtoupper($suffix)."_".md5(time().mt_rand());
if (empty($dir) == TRUE){
$dir = sys_get_temp_dir();
}
$file = $dir.'/'.$name.".".$suffix;
$handle = fopen($file, "w");
fclose($handle);
if (realpath($file) == TRUE)
{
register_shutdown_function(create_function("", 'if (realpath("'.$file.'") == TRUE){unlink("'.$file.'");}'));
// register_shutdown_function(array("File", 'rmtempnam'),$file);
return $file;
}
throw new Exception();
}
} // End file
echo File::tempnam(NULL,"png");
// print xxxxxxx.png
```
訂閱:
文章 (Atom)