想在您的WEB APPLICATION加入GD的功能嗎?

想要自己做出漂亮精緻的報表嗎?

那就要好好學習GD了, 它是跟PHP搭配得非常棒的圖像模組,

若您已經對PHP瞭如指掌,那學習GD將會讓您的WEB程式設計功力更加大增.

以下網站將GD的功能與教學都說明得很清楚, 若您是GD入門者, 這個網站將非常適合您.

http://www.nyphp.org/content/presentations/GDintro/gd1.php

GD 管方網站: http://www.boutell.com/gd/

<?php

//This gets today’s date
$date =time () ;

//This puts the day, month, and year in seperate variables
$day = date(‘d’, $date) ;
$month = date(‘m’, $date) ;
$year = date(‘Y’, $date) ;

//Here we generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year) ;

//This gets us the month name
$title = date(‘F’, $first_day) ;

//Here we find out what day of the week the first day of the month falls on
$day_of_week = date(‘D’, $first_day) ;

//Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero
switch($day_of_week){
case "Sun": $blank = 0; break;
case "Mon": $blank = 1; break;
case "Tue": $blank = 2; break;
case "Wed": $blank = 3; break;
case "Thu": $blank = 4; break;
case "Fri": $blank = 5; break;
case "Sat": $blank = 6; break;
}

//We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year) ;

//Here we start building the table heads
echo "<table id=wp-calendar summary=Calendar>";
echo "<CAPTION>$title $year </CAPTION>";
echo "<tr>
<TH title=Monday scope=col abbr=Monday>M</TH>
<TH title=Tuesday scope=col abbr=Tuesday>T</TH>
<TH title=Wednesday scope=col abbr=Wednesday>W</TH>
<TH title=Thursday scope=col abbr=Thursday>T</TH>
<TH title=Friday scope=col abbr=Friday>F</TH>
<TH title=Saturday scope=col abbr=Saturday>S</TH>
<TH title=Sunday scope=col abbr=Sunday>S</TH>";

//This counts the days in the week, up to 7
$day_count = 1;

echo "<tr>";
//first we take care of those blank days
while ( $blank > 0 )
{
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}

//sets the first day of the month to 1
$day_num = 1;

//count up the days, untill we’ve done all of them in the month
while ( $day_num <= $days_in_month )
{
if($day_num == $day) {
echo "<td id=today> $day_num </td>";
} else {
echo "<td > $day_num </td>";
}
$day_num++;
$day_count++;

//Make sure we start a new row every week
if ($day_count > 7)
{
echo "</tr><tr>";
$day_count = 1;
}
}

//Finaly we finish out the table with some blank details if needed
while ( $day_count >1 && $day_count <=7 )
{
echo "<td> </td>";
$day_count++;
}

echo "</tr></table>";

?>

有時候我們會在同一個頁面同時使用兩個資料庫,

若連線字串是放在CLASS的CONSTRUCTOR裡面, 通常我們都只要NEW 一次, 就可以一直保持資料庫連線,

但若兩個資料庫交替使用, 則會發生連線字串混亂的狀況.

此時應該在CLASS裡面每個FUNCTION都的MYSQL_QUERY之前都指定連線字串,

這樣就可以保持一MYSQL_QUERY對應一個資料庫的狀況了.

class sample {

function DATABASE() {
include("db1.php");

}

function FIRSTCONNECT() {
$this->DATABASE();
mysql_query("…..");
}

}

class sample2 {

function DATABASE2() {
include("db2.php");

}

function ANOTHERCONNECT() {
$this->DATABASE2();
mysql_query("…..");
}

}

$firstclass = new sample;

$secondclass = new sample2;

$secondclass->ANOTHERCONNECT(); //讀取自DB2 的資料庫

$firstclass->FIRSTCONNECT(); //讀取自DB1 的資料庫

最近在撰寫PHP程式的時候遇到了兩個花費我不少時間的問題.

第一個問題:

我們常常在設計表單的時候都會設計 新增, 刪除, 編輯的功能, 在完成這些功能之後, 我們習慣用 header("Location: xx.php"); 回到瀏覽列表. 但有時候我們在編輯成功回到瀏覽列表後(沒有錯誤訊息), 但資料卻沒有被編輯修改成功. 最糟糕的是MYSQL_ERROR() 也帶不出到底問題出在哪裡. 這個時候就可以推斷是ID 沒有被送入MYSQL.

比如說: mysql_query("UPDATE products SET title = ‘$title’ WHERE id = ‘$id’") or die(mysql_error());

這個時候, 如果你的$id 變數值是 "" 也一樣會通過指令, MYSQL 不會告訴你有錯誤. 所以無論你怎麼試都還是發現指令明明就沒問題但怎樣就是沒辦法UPDATE成功.

第二個問題:

還有另一個可能性是出在一個天殺的錯誤:

<input type="hidden" name="id" values="<?php echo $_GET['id']; ?>" />

當我們想要用隱藏表單傳送ID值的時候, 會用以上的HTML來傳送, 你發現問題出在哪裡嗎?

答案很明顯, 就是 "values" ! values 是沒有 "s"的, 多了一個"s" 你的表單就送不出去ID這個值了.

正解: <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />

若這個問題剛好與以上的問題碰在一起, 肯定會在DEBUG上花很時間.

表面上看起來很簡單的問題, 有時候會搞到我們抓狂都找不到BUG. 在這裡與大家分享經驗.

想要自己用PHP動態做出美麗的圖? 卻又不想花大錢去買別人寫好的套件?

不用慌張, 因為這個網站會教你怎麼一步一步學GD, 趕快用你的PHP中內建的GD function來畫圖吧!

動一動腦筋可以做出意想不到的效果呢.

http://www.nyphp.org/content/presentations/GDintro/

有時候我們用中文存取MYSQL資料庫資料的時候會出現亂碼,
又也許你在PHPMYADMIN看到的時候是明碼, 但用echo抓出來後卻是" ??? " 的亂碼.
又或是在儲存的時候就已經是亂碼了, 要怎麼解決呢?

可以試試看以下的方法:

mysql_query("SET NAMEs 'utf8' ");
$sql = mysql_query("SELECT * FROM wp_posts where ID = 2");

不管INSERT 或是SELECT出來, 都在mysql_query前加入

 "SET NAMES 'utf8' " 

就可以確保資料庫存取時是以UTF-8的編碼儲存, 那在做資料轉換的過程應該就可以把編碼問題解決了~

WIMP這個縮寫如果你到wikipedia 去查的話,

他會告訴你這是WIMP stands for "window, icon, menu, pointing device",

但我最近想到其實我一直習慣用WIMP,

就是 Windows Server 2003 + IIS + MYSQL + PHP,

雖然比起LAMP (Linux + Apache + MYSQL + PHP) 或 WAMP (Windows + Apache + MYSQL + PHP)組合來得遜色,

但使用快一年了也發現它的效能及功能都足夠我用了~

網上關於DEBUG WIMP的資訊其實也不多, 如果以後還發現甚麼再跟大家分享吧~

環境: Windows Server 2003 Enterprise

問題: PHP5 + MYSQL4+ IIS (找不到MYSQL模組)

解決方式: PHP4 + MYSQL4 + IIS

最近在Windows Server 2003灌PHP5 + MYSQL時頻頻遇到PHP讀不到MYSQL模組的問題,

花了不少時間去網上找解決方式, 試了都不成功, 至今原因仍不清楚,

但後來試了裝裝看PHP4的最新版本(不用PHP5), 再跑跑看,

MYSQL的模組就在PHPINFO()出現了! (記得要把php4ts.dll放在C:\Windows\system32\下)

這個文章應該對喜歡把PHP灌在WINDOWS 環境底下的人有用吧.
雖然是治標不治本的辦法(因為沒辦法用PHP5還滿懊惱的)

PHP 的 STRING FUNCTION

php 的string function 一直是處理字串的好幫手. 對於各種需求都可以在這個列表中找到.
以下列表取自: http://tw2.php.net/manual/en/ref.strings.php

Table of Contents

addcslashes — Quote string with slashes in a C style
addslashes — Quote string with slashes
bin2hex — Convert binary data into hexadecimal representation
chop — Alias of rtrim
chr — Return a specific character
chunk_split — Split a string into smaller chunks
convert_cyr_string — Convert from one Cyrillic character set to another
convert_uudecode — Decode a uuencoded string
convert_uuencode — Uuencode a string
count_chars — Return information about characters used in a string
crc32 — Calculates the crc32 polynomial of a string
crypt — One-way string encryption (hashing)
echo — Output one or more strings
explode — Split a string by string
fprintf — Write a formatted string to a stream
get_html_translation_table — Returns the translation table used by htmlspecialchars and htmlentities
hebrev — Convert logical Hebrew text to visual text
hebrevc — Convert logical Hebrew text to visual text with newline conversion
html_entity_decode — Convert all HTML entities to their applicable characters
htmlentities — Convert all applicable characters to HTML entities
htmlspecialchars_decode — Convert special HTML entities back to characters
htmlspecialchars — Convert special characters to HTML entities
implode — Join array elements with a string
join — Alias of implode
lcfirst — Make a string’s first character lowercase
levenshtein — Calculate Levenshtein distance between two strings
localeconv — Get numeric formatting information
ltrim — Strip whitespace (or other characters) from the beginning of a string
md5_file — Calculates the md5 hash of a given file
md5 — Calculate the md5 hash of a string
metaphone — Calculate the metaphone key of a string
money_format — Formats a number as a currency string
nl_langinfo — Query language and locale information
nl2br — Inserts HTML line breaks before all newlines in a string
number_format — Format a number with grouped thousands
ord — Return ASCII value of character
parse_str — Parses the string into variables
print — Output a string
printf — Output a formatted string
quoted_printable_decode — Convert a quoted-printable string to an 8 bit string
quotemeta — Quote meta characters
rtrim — Strip whitespace (or other characters) from the end of a string
setlocale — Set locale information
sha1_file — Calculate the sha1 hash of a file
sha1 — Calculate the sha1 hash of a string
similar_text — Calculate the similarity between two strings
soundex — Calculate the soundex key of a string
sprintf — Return a formatted string
sscanf — Parses input from a string according to a format
str_getcsv — Parse a CSV string into an array
str_ireplace — Case-insensitive version of str_replace.
str_pad — Pad a string to a certain length with another string
str_repeat — Repeat a string
str_replace — Replace all occurrences of the search string with the replacement string
str_rot13 — Perform the rot13 transform on a string
str_shuffle — Randomly shuffles a string
str_split — Convert a string to an array
str_word_count — Return information about words used in a string
strcasecmp — Binary safe case-insensitive string comparison
strchr — Alias of strstr
strcmp — Binary safe string comparison
strcoll — Locale based string comparison
strcspn — Find length of initial segment not matching mask
strip_tags — Strip HTML and PHP tags from a string
stripcslashes — Un-quote string quoted with addcslashes
stripos — Find position of first occurrence of a case-insensitive string
stripslashes — Un-quote string quoted with addslashes
stristr — Case-insensitive strstr
strlen — Get string length
strnatcasecmp — Case insensitive string comparisons using a "natural order" algorithm
strnatcmp — String comparisons using a "natural order" algorithm
strncasecmp — Binary safe case-insensitive string comparison of the first n characters
strncmp — Binary safe string comparison of the first n characters
strpbrk — Search a string for any of a set of characters
strpos — Find position of first occurrence of a string
strrchr — Find the last occurrence of a character in a string
strrev — Reverse a string
strripos — Find position of last occurrence of a case-insensitive string in a string
strrpos — Find position of last occurrence of a char in a string
strspn — Find length of initial segment matching mask
strstr — Find first occurrence of a string
strtok — Tokenize string
strtolower — Make a string lowercase
strtoupper — Make a string uppercase
strtr — Translate certain characters
substr_compare — Binary safe comparison of 2 strings from an offset, up to length characters
substr_count — Count the number of substring occurrences
substr_replace — Replace text within a portion of a string
substr — Return part of a string
trim — Strip whitespace (or other characters) from the beginning and end of a string
ucfirst — Make a string’s first character uppercase
ucwords — Uppercase the first character of each word in a string
vfprintf — Write a formatted string to a stream
vprintf — Output a formatted string
vsprintf — Return a formatted string
wordwrap — Wraps a string to a given number of characters

快取 CACHE 功能:

使用WEBSERVER將網頁的內容一直存取在SERVER的記憶體內,
當有瀏覽者瀏覽該網頁時, 記憶體就會直接抓出來, 是效率提高.
CACHE也可以設定時數, 也就是規定幾分鐘之內才更新.
(而不會讓網頁一直停留在同一個狀態, 讓瀏覽者以為網站都不會更新)

詳細設定可參考以下網址:

http://www.ilovejackdaniels.com/php/caching-output-in-php/