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

2016年6月27日 星期一

[php]西曆轉成民國

<?php
$date = date('Y/m/d');
$date_array = explode("/", $date);
$date_array[0] = $date_array[0] - 1911;
$date_array = $date_array[0] . '/' . $date_array[1] . '/' . $date_array[2];
echo $date_array;
?>

[wordpress]連結google calendar api的小外掛

1.先註冊成為google api 使用者(網路上教學很多,不多敘述)
2.先前往https://developers.google.com/google-apps/calendar/overview?hl=zh-TW參考php的Quickstart
3.承上,會使用Composer下載相關google calendar api的程式碼(注1.)
4.進入要設定分享的日曆進入日曆設定>>共用此日曆新增第1步所註冊的google api使用者
5.
建立一組API金鑰
6.
<?php
ini_set("display_errors", "On");
error_reporting(E_ALL & ~E_NOTICE);
require_once __DIR__ . '/vendor/autoload.php';//步驟3所下載的google calendar api
define('APPLICATION_NAME', 'Google Calendar API PHP Function');
define('SCOPES', implode(' ', array(Google_Service_Calendar::CALENDAR_READONLY)));

function getClient() {
$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPES);
$client->setDeveloperKey('XXXXXXXXX');//步驟5所建立的金鑰
$client->setAccessType('online');

return $client;
}

$client = getClient();
$service = new Google_Service_Calendar($client);
$calendarId = 'XXXXXX@group.calendar.google.com';//步驟4所要共用的日曆ID
$optParams = array(
'orderBy' => 'startTime',
'singleEvents' => TRUE,
);
$calEvents = $service->events->listEvents($calendarId, $optParams)->getItems();
?>
以上程式碼是簡易的抓取日曆上的資料
注1:Composer用法請參考[xampp]安裝laravel這篇文章








2016年5月26日 星期四

[wordpress]woocommerce自訂結帳欄位順序

function custom_override_checkout( $fields ) {
// billing address
$fields['billing']['billing_first_name']['class'] = array('form-row-last');
$fields['billing']['billing_last_name']['class'] = array('form-row-first');
$fields['billing']['billing_phone']['class'] = array('form-row-first');
$fields['billing']['billing_email']['class'] = array('form-row-wide');




// billing address order
$billing_order = array(
"billing_country",
"billing_last_name",
"billing_first_name",
"billing_company",
"billing_address_1",
"billing_address_2",
"billing_city",
"billing_state",
"billing_postcode",
"billing_email",
"billing_phone"
);


foreach($billing_order as $field)
{
$billing_ordered_fields[$field] = $fields["billing"][$field];
}

$fields["billing"] = $billing_ordered_fields;

return $fields;
}

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout' );

2016年2月2日 星期二

[xampp]安裝laravel

1.開啟命令提示字元(cmd)
2.選擇到xampp目錄下的php資料夾下載composer
    > cd C:\xampp\php

    > php -r "readfile('https://getcomposer.org/installer');" | php

3.下載完成後 composer 將被下載在 C:\xampp\php\composer.phar ,通常會習慣將其重新命名為 composer
    > rename composer.phar composer
4.測試是否安裝成功
輸入php composer
有出現 composer 版本及指令說明代表安裝成功

5.安裝 Laravel
將 PHP 的目錄加到環境變數 $PATH 裡面
> php composer global require "laravel/installer=~1.1"
6.建立新的 Laravel 專案
> php composer create-project laravel/laravel  C:\www\www_laravel --prefer-dist

7.設定 Apache 建立 VirtualHost
 在 C:\Windows\System32\drivers\etc\hosts 加上
 127.0.0.1       laravel

8.在 Apache 增加 VirtualHost
在 C:\xampp\apache\conf\extra\httpd-vhosts.conf 最後加上

   <VirtualHost *>
        DocumentRoot "C:\www\www_laravel\public"
        ServerName laravel
      <Directory "C:\www\www_laravel\public">
            AllowOverride All
            Require all granted
      </Directory>
    </VirtualHost>

9.重開 Apache 服務
10.開啟瀏覽器輸入http://laravel/


2015年9月14日 星期一

[PHP]取得檔案的目錄與上層目錄

取得現在的檔案、目錄與上層目錄
假設目前的檔案路徑為public_html/project/myphp.php

1.取得路徑+檔名
<?php
           echo __FILE__;
?>
輸出:public_html/project/myphp.php

2.取得檔名
<?php
          echo basename(__FILE__);
?>
輸出:myphp.php

3.取得不含副檔名的檔名
<?php
          echo basename(__FILE__, '.php');
?>
輸出:myphp

4.取得完整目錄路徑但不含檔名
<?php
          echo dirname(__FILE__);
?>
輸出:public_html/project

5.取得上層目錄前完整的路徑
<?php
          echo dirname(dirname(__FILE__));
?>
輸出:public_html

[Laravel]環境架設,使用docker + laradock

1.選擇使用docker + laradock在windows10的環境使用 先至 docker官方網站 下載 docker for windows   2.依照執行程式下載安裝 這邊我的電腦有遇到一些問題順便記錄下來, 在下載啟動docker時發生錯誤   Hardw...