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

2012年12月26日 星期三

Codeigniter相關參考

http://fuunkao-sekai.blogspot.tw/2011/11/codeigniter-baseurl.html

http://smartpg.pixnet.net/blog/post/25357570

https://sites.google.com/site/ageechen/work_notes/web-developing-in-php/codeigniter-mvc

http://blog.wu-boy.com/2009/08/codeigniter-%E5%88%86%E4%BA%AB%E4%B8%AD%E6%96%87%E5%AE%98%E6%96%B9%E7%B6%B2%E7%AB%99%E7%AF%84%E4%BE%8B%E7%A8%8B%E5%BC%8F%E7%A2%BC/

http://www.mrmu.com.tw/2009/10/07/codeigniter-%E5%BB%BA%E7%AB%8B%E7%B0%A1%E5%96%AE%E7%9A%84mvc%E6%9E%B6%E6%A7%8B%E7%AF%84%E4%BE%8B/

http://stackoverflow.com/questions/12808063/remove-index-php-of-codeigniter-on-iis

http://zeroplex.blogspot.tw/2012/06/codeigniter.html

http://www.hkpug.net/2008/03/03/%E6%95%99%E5%AD%B8%E6%96%87%E4%BB%B6%EF%BC%9Acodeigniter-%E5%BF%AB%E9%80%9F-php-%E6%87%89%E7%94%A8%E9%96%8B%E7%99%BC/

物件導向Object-Oriented的相關參考

http://expect7.pixnet.net/blog/post/38697222

http://www.php5.idv.tw/html.php?mod=article&do=show&shid=73

http://net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/comment-page-1/#comments

http://samueltsai.com/2012/01/18/php-object-oriented/

http://www.slideshare.net/jaceju/php-1104882

http://phpwolf.blogspot.tw/2011/05/php.html

2012年12月19日 星期三

CodeIgniter網址移除index.php(IIS設定法)

最近也開始嘗試使用CodeIgniter這個framework.
其中有一個問題就是怎麼移除網址中的index.php.
google上大多是apache的作法.
Stackoverflow的討論串提到的IIS的設定方法如下:
1.在CI所在的目錄下建立一個web.config檔
2.web.config的內容如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <system.webServer>

        <httpErrors errorMode="Detailed" />
        <asp scriptErrorSentToBrowser="true"/>

        <rewrite>
        <rules>
            <rule name="RuleRemoveIndex" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                </conditions>
                <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
            </rule>
        </rules>
        </rewrite>

    </system.webServer>

    <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true"/>
    </system.web>

</configuration>


3.存檔後,網址就可以不用包含index.php了

原文來源:
http://stackoverflow.com/questions/12808063/remove-index-php-of-codeigniter-on-iis


2012年12月18日 星期二

利用PHPMailer發信

PHP內建的mail函示僅能從php.ini設定SMTP Server並不支援指定SMTP的方式

因此強大的PHPMailer就派上用場了

以下是參考來源:

PHPMailer元件下載位置:
http://sourceforge.net/projects/phpmailer/

使用教學:
教學一:B E L L E A Y A 雜七雜八創作小窩

教學二:艾瑞克的回憶錄

教學三:寶尼

2012年7月11日 星期三

PHP教學參考網站

1.參考資源一
http://emn178.pixnet.net/blog/post/78014066

待續....

線上寫Code的服務

1.JS
http://jsfiddle.net/

2.PHP
http://codepad.viper-7.com/

待續....

2012年5月2日 星期三

難字寫入MSSQL資料庫變成?問號的解決方式

問題:
頁面已設定為UTF-8編碼,資料庫欄位也設定為nvarchar,但難字的部份仍然為?問號.是什麼狀況?

解決方式:
在SQL Command 裡面加上 N 就可以修復此問題.
範例如下:
UPDATE Mydb Set MyField = N'塵蟎' WHERE Mycode = '123'

INSERT INTO Mydb (MyField) VALUES(N'塵蟎')

2012年2月14日 星期二

PHP 出现Notice: Use of undefined constant 的解决方案

資料來源:http://www.sanywork.com/20090727612.html


進入網站會出現大量類似下面的提示,但是可以正常顯示和運行
Notice: Use of undefined constant ctbTitle - assumed 『ctbTitle' in d:\ctb1.5\ctb\include\config.php on line 23…


答案:這些是 PHP 的提示而非報錯,PHP 本身不需要事先聲明變量即可直接使用,但是對未聲明變量會有提示。一般作為正式的網站會把提示關掉的,甚至連錯誤信息也被關掉
關閉 PHP 提示的方法
搜索php.ini:
error_reporting = E_ALL
改為:
error_reporting = E_ALL & ~E_NOTIC

2012年1月4日 星期三

如何更正系統時間 timezone_set

資料來源:http://tinyurl.com/7ddzvv7


相信很多虛擬主機都會碰到時間的問題,比如說少8小時,或者是多8小時,現在只要在執行php的前端加上
這樣就會更新到正確時間了,這樣在使用 time mktime() 就沒啥問題了
或者逝去系統改 php.ini檔案
;Defines the default timezone used by the date functions
date.timezone = Asia/Taipei

2012年1月2日 星期一

phpmyadmin 出現關聯資料表的附加功能未能啟動解決方法

資料來源: http://tinyurl.com/7zxcwf4

1.建立phpmyadmin的資料庫
使用phpmyadmin/scripts/create_tables.sql

2.更動config.inc.php
加入:
$cfg['Servers'][$i]['pmadb'] = ‘phpmyadmin’;
$cfg['Servers'][$i]['bookmarktable'] = ‘pma_bookmark’;
$cfg['Servers'][$i]['relation'] = ‘pma_relation’;
$cfg['Servers'][$i]['table_info'] = ‘pma_table_info’;
$cfg['Servers'][$i]['table_coords'] = ‘pma_table_coords’;
$cfg['Servers'][$i]['pdf_pages'] = ‘pma_pdf_pages’;
$cfg['Servers'][$i]['column_info'] = ‘pma_column_info’;
$cfg['Servers'][$i]['history'] = ‘pma_history’;
$cfg['Servers'][$i]['designer_coords'] = ‘pma_designer_coords’;
$cfg['Servers'][$i]['tracking'] = ‘pma_tracking’;

3.重新啟動IIS或apache

2011年10月19日 星期三

php 傳送POST到別的URL並取得回應內容 使用fsockopen

資料來源:http://blog.hsin.tw/2009/php-post-method-fsockopen/


//接收POST參數的URL
//POST參數,在這個陣列裡,索引是name,值是value,沒有限定組數
$postdata = array('post_name'=>'post_value','acc'=>'hsin','nick'=>'joe');
//函式回覆的值就是取得的內容
$result = sendpost($url,$postdata);
function sendpost($url, $data){
//先解析url 取得的資訊可以看看http://www.php.net/parse_url
$url = parse_url($url);
$url_port = $url['port']==''?(($url['scheme']=='https')?443:80):$url['port'];
if(!$url) return "couldn't parse url";
//對要傳送的POST參數作處理
$encoded = "";
while(list($k,$v)=each($data)){
  $encoded .= ($encoded?'&':'');
  $encoded .= rawurlencode($k)."=".rawurlencode($v);
}
//開啟一個socket
$fp = fsockopen($url['host'],$url_port);
if(!$fp) return "Failed to open socket to ".$url['host'];
//header的資訊
fputs($fp,'POST '.$url['path'].($url['query']?'?'.$url['query']:'')." HTTP/1.0rn");
fputs($fp,"Host: ".$url['host']."n");
fputs($fp,"Content-type: application/x-www-form-urlencodedn");
fputs($fp,"Content-length: ".strlen($encoded)."n");
fputs($fp,"Connection: closenn");
fputs($fp,$encoded."n");
//取得回應的內容
$line = fgets($fp,1024);
if(!eregi("^HTTP/1.. 200", $line)) return;
$results = "";
$inheader = 1;
while(!feof($fp)){
  $line = fgets($fp,2048);
  if($inheader&&($line == "n" || $line == "rn")){
    $inheader = 0;
  }elseif(!$inheader){
    $results .= $line;
  }
}
fclose($fp);
return $results;
}


相關參考:
http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/

PHP CURL 發送 GET 和 POST 語法

資料來源:http://fq-story.blogspot.com/2009/05/php-curl-get-post.html

PHP CURL

1、http的get傳送

$ch = curl_init("/") ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ;
$output = curl_exec($ch) ;
$fh = fopen("out.html", 'w') ;
fwrite($fh, $output) ;
fclose($fh) ;

2、http的post傳送

EX1

$URL="www.mysite.com/test.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "Data1=blah&Data2=blah");curl_exec ($ch);
curl_close ($ch);


EX2

//extract data from the post
extract($_POST) ;
//set POST variables
$url = '/get-post.php' ;
$fields = array(
'lname'=>urlencode($last_name) ,
'fname'=>urlencode($first_name) ,
'title'=>urlencode($title) ,
'company'=>urlencode($institution) ,
'age'=>urlencode($age) ,
'email'=>urlencode($email) ,
'phone'=>urlencode($phone)
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&' ; }
rtrim($fields_string ,'&') ;
//open connection
$ch = curl_init() ;
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL,$url) ;
curl_setopt($ch, CURLOPT_POST,count($fields)) ;
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string) ;
//execute post
$result = curl_exec($ch) ;
//close connection
curl_close($ch) ;

相關參考:
http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/
http://blog.roodo.com/esabear/archives/16358749.html

2011年7月12日 星期二

利用 Google Analytics API 抓取資料

資料來源:
1.http://tech.ed65.com/2010/12/02/%E5%88%A9%E7%94%A8-google-analytics-api-%E6%8A%93%E5%8F%96%E8%B3%87%E6%96%99-php/
2.http://www.askaboutphp.com/63/google-analytics-api-class-for-php.html

利用 Google Analytics API 抓取資料-PHP


<?php
// include the Google Analytics PHP class
include "googleanalytics.class.php";
try {
// create an instance of the GoogleAnalytics class using your own Google {email} and {password}
$ga = new GoogleAnalytics('email','密碼');

// set Google Analytics ID - 格式為 'ga:123456';
$ga->setProfile('google analytics ID');

// set the date range we want for the report - format is YYYY-MM-DD
$ga->setDateRange('2010-11-29','2010-12-01');

// get the report for date and country filtered by Australia, showing pageviews and visits
$report = $ga->getReport(
array('dimensions'=>urlencode('ga:date,ga:country'),
'metrics'=>urlencode('ga:pageviews,ga:visits'),
'filters'=>urlencode('ga:country=@Taiwan'),
'sort'=>'-ga:pageviews'
)
);

//print out the $report array
print_r($report);

} catch (Exception $e) {
print '錯誤: ' . $e->getMessage();
}
?>
其中 Google Analytics ID 為網址中xxxxx的部份 >>
https://www.google.com/analytics/reporting/?reset=1&id=xxxxx&pdr=20101101-20101201
請於此下載需要呼叫的檔案: googleanalytics.class

2011年6月29日 星期三

PHP中單引號跟雙引號有什麼不同?

資料來源:http://www.neo.com.tw/archives/958

單引號跟雙引號到底有什麼不同?

PHP 會解譯「雙引號」字串內的變數,而「單引號」則視為純字串出,PHP 不會再處理單引號內的內容。

2011年6月27日 星期一

PHP補零的作法

資料來源:http://blog.hsin.tw/2009/php-pad-a-string/

PHP有內建的函數可以方便的做補齊位數的函數,
google了一番找到清楚的說明,文章轉載如下:


會找到有些使用sprintf函式的方法 像下面這樣
$var = 1;
echo sprintf("%02d", $var);
其實php本身就有一個專門可以補齊位數的函式 : str_pad()
string str_pad ( string $input , int $pad_length [, string $pad_string= " " [, int $pad_type= STR_PAD_RIGHT ]] )
$input : 原字串
$pad_length : 補齊後的位數
$pad_string : 用來補齊的字串
$pad_type : 補齊的方式 有三種,STR_PAD_RIGHT (由右邊補)、STR_PAD_LEFT (由左邊補)、STR_PAD_BOTH (左右兩邊都補), 預設為STR_PAD_RIGHT
所以其實不只可以補零,要補什麼字都可以
而以補零來舉例的話就是


$value = 7;
//將數字由左邊補零至三位數
$value = str_pad($value,3,'0',STR_PAD_LEFT);
echo $value;
// 結果會印出 007;
 
//下面這是document裡的例子
$input = "Alien";
echo str_pad($input, 10);                      // produces "Alien     "
echo str_pad($input, 10, "-=", STR_PAD_LEFT);  // produces "-=-=-Alien"
echo str_pad($input, 10, "_", STR_PAD_BOTH);   // produces "__Alien___"
echo str_pad($input, 6 , "___");               // produces "Alien_"

2011年6月17日 星期五

Warning: Cannot modify header information - headers already sent by解法

資料來源:http://amjet.dyndns.biz/blog/IT/?p=12


寫 php 時常遇到這個錯誤訊息,解法也很簡單,如果 php 有 include 其他程式檔的話檢查 <?php 的前面不可以有任何的空行或文字,?> 後面也不要有空行和其他文字就可以了。
2007/12/25 加註:
有些 editor 在處理 utf-8 編碼文件檔時,會在檔案最前面加上幾個 byte 的檔頭,一般編輯時看不到,利用 UltraEditor、NotePad++ 的 Hex mode 可以看到及修改,這種檔案也會造成上述的錯誤,也有看過這種 jsp 檔案 java 無法 compile 的情形。

Undefined index 錯誤PHP

資料來源:http://plog.tcc.edu.tw/post/530/12708

治標不治本的就是將php.ini內的reporting部份修改,讓notice不顯示
error_reporting = E_ALL; display all errors, warnings and notices
改成
error_reporting = E_ERROR & ~E_NOTICE & ~E_WARNING

不然
isset($_GET["page"])做個if-else判斷!!

或者在這段敘述前面加上'@'表示這行敘述如果有錯誤或是警告時不要輸出
如:@$page=$_GET["page"]

php5.3開始出現的Function ereg() is deprecated Error問題解決辦法

資料來源:http://www.liuhuadong.com/archives/727/index.html


PHP 5.3 ereg() 無法正常使用,提示「Function ereg() is deprecated Error」。問題根源是php中有兩種正則表示方法,一個是posix,一個是perl,php6打算廢除posix的正則表示方法所以後來就加了個 preg_match。此問題解決辦法很簡單,在ereg前加個過濾提示信息符號即可:把ereg()變成@ereg()。這樣屏蔽了提示信息,但根本問 題還是沒有解決,php在5.2版本以前ereg都使用正常,在5.3以後,就要用preg_match來代替ereg。所以就需要變成這樣,原來:
ereg("^[0-9]*$",$page)
變成:
preg_match("/^[0-9]*$/",$page)
特別提醒:posix與perl的很明顯的表達區別就是是否加斜槓,所以與ereg相比,後者在正則的前後分別增加了兩個」/」符號,不能缺少。
Tips:此問題在php5.2之前版本不會出現。

幾個用PHP產生縮圖的參考

1.資料來源:
http://blog.twkang.net/2006/08/25/php-%E7%94%A2%E7%94%9F%E7%B8%AE%E5%9C%96%E7%9A%84%E6%96%B9%E6%B3%95/

2.資料來源:http://inspire.twgg.org/c/programming/php/using-php-function-imagecopyresized-gd-the-establishment-of-high-precision-thumbnail.html

3.資料來源:http://blog.ring.idv.tw/comment.ser?i=173

4.資料來源:http://blog.longwin.com.tw/2007/08/php_image_resize_2007/

最後參考了資料來源4的PHP 等比例縮圖程式的寫作方法

2011年3月22日 星期二

ASP和PHP語法對照表

資料來源:http://www.design215.com/toolbox/asp.php

要改寫某些案子的時候就可以拿來參考.