顯示具有 網頁設計/編程 標籤的文章。 顯示所有文章
顯示具有 網頁設計/編程 標籤的文章。 顯示所有文章

2009年7月10日 星期五

使用PHP mail()寄送UTF-8編碼之電子郵件

常遇到的問題是,「郵件標題」或「寄件者」是亂碼的問題
主要的原因在於,電子郵件標準格式中,
表頭的部分不允許使用雙位元的文字,
所以,使用mb_encode_mimeheader()函式
將雙位元文字編碼為單位元字串。
範例:
mb_internal_encoding('UTF-8');
$subject=mb_encode_mimeheader('訂單', 'UTF-8');
$message= $html; //HTML格式的信件內容
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .=
"From: ".mb_encode_mimeheader('訂購網', 'UTF-8')." <xxxx@xxxx.xxx.xx>\r\n";
mail($to,$subject,$message,$headers);
因mb_encode_mimeheader()預設的字串編碼為西方ISO-8859-1,
而此範例使用UTF-8編碼中文字,
故程式中需使用mb_internal_encoding()將內部預設編碼改為UTF-8
參考資料:
最新PHP+MySQL+AJAX網頁程式設計(旗標出版)

 

轉貼自:http://jck11.pixnet.net/blog/post/21932761#comments

2009年7月6日 星期一

IE hack

要注意的是前面的符號:

_border:1px;/* IE6 hack */

*border:1px;/* IE6,7 hack */

如果只要IE7的話,可以這樣做:

*border:1px;/* IE6,7 hack */

_border:1px;/* IE6 hack */

 

原理是根據css的規則,后面的會取代前面的,前面的是for IE6和7,后面的for IE6,

也就是說后面的IE6會取代前面的IE6,7的IE6。

2009年5月25日 星期一

"Cannot modify header information"的解决方法

If you got this message: "Warning: Cannot modify header information - headers already sent by ...."
如果在执行php程序时看到这条警告:"Warning: Cannot modify header information - headers already sent by ...."

Few notes based on the following user posts:
有以下几种解决方法:

1. Blank lines (空白行):
Make sure no blank line after of the calling php scrīpt.
检查有 后面没有空白行,特别是include或者require的文件。不少问题是这些空白行导致的。

2. Use exit statement (用exit来解决):
Use exit after header statement seems to help some people
在header后加上exit();
header ("Location: xxx");
exit();

3. PHP has this annoying problem, if your HTML goes before any PHP code or any header modification before redirecting to certain page, it ll said "Warning: Cannot modify header information - headers already sent by ...." Basically anytime you output to browser, the header is set and cannot be modified. So two ways to get around the problem:

3a. Use Javascrīpt (用Javascrīpt来解决):
self.location( file.php );"; ?>
Since it s a scrīpt, it won t modify the header until execution of Javascrīpt.
可以用Javascrīpt来代替header。另外需要注意,采用这种方法需要浏览器支持Javascrīpt.

3b. Use output buffering (用输出缓存来解决):

... HTML codes ...

This will save the output buffer on server and not output to browser yet, which means you can modify the header all you want until the ob_end_flush() statement. This method is cleaner than the Javascrīpt since Javascrīpt method assumes the browser has Javascrīpt turn on. However, there are overhead to store output buffer on server before output, but with modern hardware I would imagine it won t be that big of deal. Javascrīpt solution would be better if you know for sure your user has Javascrīpt turn on on their browser.

就像上面的代码那样,这种方法在生成页面的时候缓存,这样就允许在输出head之后再输出header了。本站的许愿板就是采用这种方法解决的header问题。

4.set output_buffering = On in php.ini (开启php.ini中的output_buffering )
set output_buffering = On will enable output buffering for all files. But this method may slow down your php output. The performance of this method depends on which Web server you re working with, and what kind of scrīpts you re using.
这种方法和3b的方法理论上是一样的。但是这种方法开启了所有php程序的输出缓存,这样做可能影响php执行效率,这取决于服务器的性能和代码的复杂度。

出處:http://www.phpchina.com/html/47/26247-8026.html

2009年5月24日 星期日

mysql 遠端存取

這幾天要忙專題,因為有跟人合作的關系,想到資料庫要同步存取,結果就研究了一下。

原來用遠端存取是不可以用root的身份的,必須新增一個用戶,把它弄到好像root的身份就可以了。

還有一點,如果在設定文件里有skip-networking的話應該是要注解掉它吧,可是不確定,因為目前在用的沒有這個.

2009年4月20日 星期一

overlay的做法

當我們去到某些網站時可以看到他們的提示窗口滿特別的,不再是用alert了,

而是改用一個層,覆蓋后面的物件,簡單來講,去igoogle就知道了。

怎么做到的呢?其實就是用css+javascript,下面就是一些代碼:

這就是最底層,z-index設為9998,覆蓋了以下的物件:

#overlay_window{
height:100%;
width:100%;(覆蓋整個頁面)
background-color:#000;
z-index:9998;
position:absolute;
margin:0px;
top:0px;
left:0px;
display:none;(初始時不顯示)
}

要顯示的內容:

#overlay_contain{
width:750px;(自己設定你要的寬度)
position:absolute; 
z-index:9999;
margin-left:-375px;(居中,要設為auto也可以)
left:50%;
display:none;
}

html:

<div id=overlay_window></div>

<div id=overlay_contain></div>

如何顯示:

在這里我用了jquery的寫法:

$(#button”).click(function()

{

$(“#overlay_window”).fadeTo(‘slow’,0.5,function()

{

       $(“#overlay_window”).fadeIn(‘slow’);

       $(“#overlay_contain”).fadeIn(‘slow’);

})

});

或者原裝javascript(想像出來的,沒經過測試,僅為參考)

document.getElementById(‘button’).onclick=function()

{

var win=document.getElementById(‘overlay_window’);

var contain=document.getElementById(‘overlay_contain’);

win.style.display=’block’;

contain.style.display=’block’;

win.style.opacity=’0.5’;//IE的話不支持,可能要另想辦法

} ;

(本文乃原創文章,轉載請注明出處)

windows架站包-apache2triad推介+升級php到5.29的方法

 

最近發現了這個好康,這是一個簡易架站包,內容包括有:

apache2.2.0

mysql 5.0.18

postgreSQL 8.1.2

Openssl 0.9.8a

slimftpd 3.18

xmail 1.22

php 5.1.2

perl 5.8.7

Python 2.3

AWStats

PHPmyadmin

phpPgAdmin

pgAdmin

等等….其實還有很多,有興趣可以到官網看看,google一下就有了~

 

還有一點要提醒的是作者已經對這個套件停止了更新,想不想下載就看各位了。

 

更新php5.12到5.29的方法:

由于作者已經停止了更新,所以更新就要靠自己了,以下就是更新的方法:

1.) 去php官網下載php-5.2.9-1-win32-installer.msi
2.) 把你舊的php文件夾C:\apache2triad\php 改名到 to C:\apache2triad\php-old,以免更新失敗后無法從來(當作backup)
3.) 安裝剛才下載的php到C:\apache2triad\php 。選擇全部選項, 當問你用那個apache時選Apache2.2 
4.) 設定apache選項; 在 C:\apache2triad\conf 文件夾里開啟 httpd.conf。找到 #php config (大概在1076行) ,新的php已經沒有了bin的文件夾,所以有php下的bin路徑都改掉,我改了(把bin刪掉):

LoadFile php\php5ts.dll
LoadFile php\fdftk.dll

好像就只有這2個而已,很久以前的事了,不知道記得的對不對~

還有,要注解掉

#LoadFile php\bin\ntwdblib.dll(#就是注解)
5.)重新啟動你的作業系統。

原文出處(英文版):Upgrading PHP from 5.1.x to 5.2.9

中文版由小葉翻譯,轉帖請注明出處,謝謝!

2009年1月27日 星期二

div居中的超簡單方法

css:

body{
margin-left:-300px(你div的width的一半);
}
center_div{
position:relative
left:50%;
width:600px;
}

很簡單是吧?如果不要用body的話,可以用一個div把你要居中的div包起來
css:

body{}

parent_div{
width:100%(讓他跟body同寬);
margin-left:-300px(你div的width的一半);
}
center_div{
position:relative
left:50%;
width:600px;
}


如果不行的話試著在html上面加上
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

(本文乃原創文章,轉載請注明出處)

不用javascript只用div+css實現的toolTip做法 ( ie上的z-index )

最近都在忙著做系所網頁,在某一個頁面上想做出類似ToolTip的功能,本來使用了jquery的TooTip plugin來實現,不過發現到了原來可以用css來實現,代碼少了很多。

css:
.userpoint{
width:100px;
float:left;
cursor:pointer;
}
.tooltip{
position:relative;//最重要的
border:solid 1px;
background-color:blue;
display:none;
width:150px;
left:5px;
top:-5px;
z-index:3000;//最重要的
}
.userpoint:hover .tooltip,tooltip:hover{//最重要的
display:block;
}

html的內容:
< div class="userpoint"> point to me < div class="tooltip" >這是用css來實現的功能</div></div>


效果:

point to me
這是用css來實現的功能

point to me
這是用css來實現的功能

point to me
這是用css來實現的功能


這樣就實現了,是不是超簡單呢?
這只是基本的范例,很難看吧,但是有很大的自由度,除了標示最重要的更改要注意之外,其他都可以改,包括顏色,大小等等,可以在tooltip的div再加入任何東西。
比起要用jquery的ToolTip plugin,壓縮后還有整整5kb多,而且自由度又受限制(要照著一定格式),我之前因為要達到某些效果而又要照著格式,結果違背了網頁標準。
而用css甚至不需要1kb,又符合網頁標準
這就給我上了一課,不要什么都靠javascript。

*要留意的是z-index在ie上有不同的處理方法,我也不是很清楚,之前我是吧tooltip的parent(userpoint)的position是設為absolute的,結果z-index:3000就變無效了,發現tooltip一定要設為relative,他的parent一定要是預設的static,這樣z-index才能產生效果,當然,ie以外的瀏覽器是沒這些問題的。


如果不行的話試著在html上面加上
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

(本文乃原創文章,轉載請注明出處)