2007年8月23日 星期四

無間斷圖片跑馬燈

男丁格爾's 脫殼玩
那看到了一種做法無間斷圖片跑馬燈
看似不錯,但畫面會被拉長...

因綠際會下...不小心在網路上找到了下面這方法
唯因為原作者己不可考...故無法列出處(若原作者有看到,請來信通知,好讓我補上,謝謝)


原始程式如下....原作者的註解我就不做更動
中文部份是我自己加上的註解

//這是要滾動的內容,最好用div包起來
<div id="scrollbarDemo">
這裡是要滾動的內容
</div>

<SCRIPT type="text/javascript">
//這一塊是主要程式運作的地方
var __scrollBarControl = null;
var __divinnerHTML=null;
var __firstTime=true;
function innerBarProp(barID, width, height, interval, direction)
{
 this.barID = barID;
 this.width = width;
 this.height = height;
 this.interval = interval;
 this.direction = direction;
 this.stopScroll = false;
 this.maxValue = 0;
 this.preValue = 0;
}
function scrollBar()
{
 this.barsArray = new Array();
 //save current object
 __scrollBarControl = this;
}
//////////////////////////////////////////////////////////////////
// add scrollbar to bar list and set properties
// parameters:
// barID: HTML's tag <DIV>'s id property
// (for js access the DIV object)
// width: define the scrollbar's width
// height: define the scrollbar's height
// interval: define the scroll speed
// ( scroll up/down per XX millinSecond )
// direction: scroll direction's defined
// "up"
// "down"
// "left"
// "right"
//////////////////////////////////////////////////////////////////
scrollBar.prototype.addBar = function(barID, width, height, interval, direction)
{
 //check parameters
 var paraCount = arguments.length;
 if ( paraCount < 1 )
 {
  alert("parameters count incorect!");
  return;
  //throw "parameters count inccorect!";
 }

 //width's default value
 if ( typeof( width ) == "undefined" )
 {
  var width = 100;
 }

 //height's default value
 if ( typeof( height ) == "undefined" )
 {
  var height = 100;
 }

 //interval's default value
 if ( typeof( interval ) == "undefined" )
 {
  var interval = 1000;
 }
 
 //direction's default value
 if ( typeof( direction ) == "undefined" )
 {
  var direction = "up";
 }

 //create scrollbar's inner properties
 var barProp = new innerBarProp(barID, width, height, interval, direction);
 var objBar = document.getElementById(barID);
 if(__divinnerHTML!=null)
  objBar.innerHTML=__divinnerHTML;
 else
  __divinnerHTML=objBar.innerHTML;
 var barCount = this.barsArray.length;
 this.barsArray[barCount] = barProp;
}
scrollBar.prototype.clear = function()
{
 for(i=0;i<this.barsArray.length;i++)
  this.barsArray.pop();
}
scrollBar.prototype.createScrollBars = function()
{
 //get bar's count
 var barCount = this.barsArray.length;
 //if no bar add to scrollControl do nothing
 if ( barCount == 0 )
 {
  return;
 }

 //init scroll bars
 for ( var i=0; i<barCount; i++ )
 {
  var objBarID = this.barsArray[i].barID;
  //if typeof objBarID is object
  // that's meaning it inited
  //if typeof objBarID is string
  // init that scroll bar
  if ( typeof( objBarID ) == "string" )
  {
   //get scroll <DIV> object
   var objBar = document.getElementById( objBarID );
   if (objBar == null)
   {
    //objBarID is not exist
    if ( document.readyState == "complete" || document.readyState == "loaded" )
    {
     //the objBarID not exists in current document
     //throw "the objBarID is not exists.";
     alert("ScrollBar[" + objBarID + "]: not exist!");
     return;
    }
    else
    {
     //wait for document to load objBarID
     window.setTimeout("__scrollBarControl.createScrollBars()",50);
     //exit processing..........
     //and wait next time callbak
     return;
    }
   }
   //update barID
   this.barsArray[i].barID = objBar;
  }
 }

 for ( var i=0; i<barCount; i++ )
 {
  this.innerInitBar(i);
 }
}
scrollBar.prototype.innerInitBar = function (index)
{
 //get properties
 var barID = this.barsArray[index].barID;
 var width = this.barsArray[index].width;
 var height = this.barsArray[index].height;
 var interval = this.barsArray[index].interval;
 var direction = this.barsArray[index].direction;
 var maxValue = 0;

 //set scrollBar's properties
 with(barID)
 {
  style.width = width;
  style.height = height;
  noWrap=true;
  switch( direction )
  {
   //這裡是實際決定滾動方向及內容的地方
   //有up,down,left,right
   case "up":
    maxValue = Math.max(scrollHeight, height);
    style.overflowX = "visible";
    style.overflowY = "hidden";
    //宣告barHtml來放代入的div裡面的內容
    var barHtml = innerHTML;
    //將之複製二次,並擺在一個table裡面
    //若外面傳入的div裡面的table己寫好
    //這裡則可以直接省略,直接使用innerHTML = barHtml+barHtml;來代替
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
    newHtml += " <tr height='20'>\n";
    newHtml += " <td> \n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += "</table>\n";
    innerHTML = newHtml;
    break;
   case "down":
    maxValue = Math.max(scrollHeight, height);
    style.overflowX = "visible";
    style.overflowY = "hidden";
    var barHtml = innerHTML;
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += "</table>\n";
    innerHTML = newHtml;
    scrollTop = maxValue;
    break;
   case "left":
    maxValue = Math.max(scrollWidth, width);
    style.overflowX = "hidden";
    style.overflowY = "visible";
    var barHtml = barID.innerHTML;
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
    newHtml += " <tr>\n";
    newHtml += " <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += "</table>\n";
    innerHTML = newHtml;
    break;
   case "right":
    maxValue = Math.max(scrollWidth, width);
    style.overflowX = "hidden";
    style.overflowY = "visible";
    var barHtml = innerHTML;
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
    newHtml += " <tr>\n";
    newHtml += " <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += "</table>\n";
    innerHTML = newHtml;
    scrollLeft = maxValue;
    break;
   default:
    //throw "direction is inccorect!";
    alert("ScrollBar[" + id + "]: direction is incorect!");
    return;
  }

  //set mouse events
  onmouseover = new Function("__scrollBarControl.mouseEvt(" + index + ",true);");
  onmouseout = new Function("__scrollBarControl.mouseEvt(" + index + ",false);");
  if(__firstTime)
  {
   __firstTime=false;
   window.setInterval("__scrollBarControl.scroll(" + index + ");",interval);
  }
  //save maxValue
  this.barsArray[index].maxValue = maxValue;
 }
}
scrollBar.prototype.mouseEvt = function(index, stop)
{
 this.barsArray[index].stopScroll = stop;
}
scrollBar.prototype.scroll = function(index)
{
 //get properties
 var barID = this.barsArray[index].barID;
 var width = this.barsArray[index].width;
 var height = this.barsArray[index].height;
 var interval = this.barsArray[index].interval;
 var direction = this.barsArray[index].direction;
 var stopScroll = this.barsArray[index].stopScroll;
 var preValue = this.barsArray[index].preValue;
 var maxValue = this.barsArray[index].maxValue;

 if ( stopScroll == true ) return;

 switch(direction)
 {
  case "up":
   preValue++;
   if ( preValue >= maxValue )
   {
    preValue = 0;
   }
   barID.scrollTop = preValue;
   break;
  case "down":
   preValue--;
   if ( preValue <= 0 )
   {
    preValue = maxValue;
   }
   barID.scrollTop = preValue;
   break;
  case "left":
   preValue++;
   if ( preValue >= maxValue )
   {
    preValue = 0;
   }
   barID.scrollLeft = preValue;
   break;
  case "right":
   preValue--;
   if ( preValue <=0 )
   {
    preValue = maxValue;
   }
   barID.scrollLeft = preValue;
   break;
 }
 this.barsArray[index].preValue = preValue;
}
//=================end of file===========================
</SCRIPT>
<SCRIPT type="text/javascript">
//這裡是使用在網頁上的
var scrollBarControl = new scrollBar();
MoveTo("up");
function MoveTo(d)
{
 //清除剛才宣告的scrollbarcontrol
 scrollBarControl.clear();
 //新增一欲滾動的ID,五個參數分別為
 //欲滾動的區塊ID,寬,高,速度,方向
 scrollBarControl.addBar("scrollbarDemo", 228, 120, 100, d);
 scrollBarControl.createScrollBars();
}
</SCRIPT>

男丁格爾's 脫殼玩
那看到了一種做法無間斷圖片跑馬燈
看似不錯,但畫面會被拉長...

因綠際會下...不小心在網路上找到了下面這方法
唯因為原作者己不可考...故無法列出處(若原作者有看到,請來信通知,好讓我補上,謝謝)


原始程式如下....原作者的註解我就不做更動
中文部份是我自己加上的註解

//這是要滾動的內容,最好用div包起來
<div id="scrollbarDemo">
這裡是要滾動的內容
</div>

<SCRIPT type="text/javascript">
//這一塊是主要程式運作的地方
var __scrollBarControl = null;
var __divinnerHTML=null;
var __firstTime=true;
function innerBarProp(barID, width, height, interval, direction)
{
 this.barID = barID;
 this.width = width;
 this.height = height;
 this.interval = interval;
 this.direction = direction;
 this.stopScroll = false;
 this.maxValue = 0;
 this.preValue = 0;
}
function scrollBar()
{
 this.barsArray = new Array();
 //save current object
 __scrollBarControl = this;
}
//////////////////////////////////////////////////////////////////
// add scrollbar to bar list and set properties
// parameters:
// barID: HTML's tag <DIV>'s id property
// (for js access the DIV object)
// width: define the scrollbar's width
// height: define the scrollbar's height
// interval: define the scroll speed
// ( scroll up/down per XX millinSecond )
// direction: scroll direction's defined
// "up"
// "down"
// "left"
// "right"
//////////////////////////////////////////////////////////////////
scrollBar.prototype.addBar = function(barID, width, height, interval, direction)
{
 //check parameters
 var paraCount = arguments.length;
 if ( paraCount < 1 )
 {
  alert("parameters count incorect!");
  return;
  //throw "parameters count inccorect!";
 }

 //width's default value
 if ( typeof( width ) == "undefined" )
 {
  var width = 100;
 }

 //height's default value
 if ( typeof( height ) == "undefined" )
 {
  var height = 100;
 }

 //interval's default value
 if ( typeof( interval ) == "undefined" )
 {
  var interval = 1000;
 }
 
 //direction's default value
 if ( typeof( direction ) == "undefined" )
 {
  var direction = "up";
 }

 //create scrollbar's inner properties
 var barProp = new innerBarProp(barID, width, height, interval, direction);
 var objBar = document.getElementById(barID);
 if(__divinnerHTML!=null)
  objBar.innerHTML=__divinnerHTML;
 else
  __divinnerHTML=objBar.innerHTML;
 var barCount = this.barsArray.length;
 this.barsArray[barCount] = barProp;
}
scrollBar.prototype.clear = function()
{
 for(i=0;i<this.barsArray.length;i++)
  this.barsArray.pop();
}
scrollBar.prototype.createScrollBars = function()
{
 //get bar's count
 var barCount = this.barsArray.length;
 //if no bar add to scrollControl do nothing
 if ( barCount == 0 )
 {
  return;
 }

 //init scroll bars
 for ( var i=0; i<barCount; i++ )
 {
  var objBarID = this.barsArray[i].barID;
  //if typeof objBarID is object
  // that's meaning it inited
  //if typeof objBarID is string
  // init that scroll bar
  if ( typeof( objBarID ) == "string" )
  {
   //get scroll <DIV> object
   var objBar = document.getElementById( objBarID );
   if (objBar == null)
   {
    //objBarID is not exist
    if ( document.readyState == "complete" || document.readyState == "loaded" )
    {
     //the objBarID not exists in current document
     //throw "the objBarID is not exists.";
     alert("ScrollBar[" + objBarID + "]: not exist!");
     return;
    }
    else
    {
     //wait for document to load objBarID
     window.setTimeout("__scrollBarControl.createScrollBars()",50);
     //exit processing..........
     //and wait next time callbak
     return;
    }
   }
   //update barID
   this.barsArray[i].barID = objBar;
  }
 }

 for ( var i=0; i<barCount; i++ )
 {
  this.innerInitBar(i);
 }
}
scrollBar.prototype.innerInitBar = function (index)
{
 //get properties
 var barID = this.barsArray[index].barID;
 var width = this.barsArray[index].width;
 var height = this.barsArray[index].height;
 var interval = this.barsArray[index].interval;
 var direction = this.barsArray[index].direction;
 var maxValue = 0;

 //set scrollBar's properties
 with(barID)
 {
  style.width = width;
  style.height = height;
  noWrap=true;
  switch( direction )
  {
   //這裡是實際決定滾動方向及內容的地方
   //有up,down,left,right
   case "up":
    maxValue = Math.max(scrollHeight, height);
    style.overflowX = "visible";
    style.overflowY = "hidden";
    //宣告barHtml來放代入的div裡面的內容
    var barHtml = innerHTML;
    //將之複製二次,並擺在一個table裡面
    //若外面傳入的div裡面的table己寫好
    //這裡則可以直接省略,直接使用innerHTML = barHtml+barHtml;來代替
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
    newHtml += " <tr height='20'>\n";
    newHtml += " <td> \n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += "</table>\n";
    innerHTML = newHtml;
    break;
   case "down":
    maxValue = Math.max(scrollHeight, height);
    style.overflowX = "visible";
    style.overflowY = "hidden";
    var barHtml = innerHTML;
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += " <tr>\n";
    newHtml += " <td height='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += "</table>\n";
    innerHTML = newHtml;
    scrollTop = maxValue;
    break;
   case "left":
    maxValue = Math.max(scrollWidth, width);
    style.overflowX = "hidden";
    style.overflowY = "visible";
    var barHtml = barID.innerHTML;
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
    newHtml += " <tr>\n";
    newHtml += " <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += "</table>\n";
    innerHTML = newHtml;
    break;
   case "right":
    maxValue = Math.max(scrollWidth, width);
    style.overflowX = "hidden";
    style.overflowY = "visible";
    var barHtml = innerHTML;
    var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
    newHtml += " <tr>\n";
    newHtml += " <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " <td width='" + maxValue + "' valign='top'>\n";
    newHtml += barHtml + "\n";
    newHtml += " </td>\n";
    newHtml += " </tr>\n";
    newHtml += "</table>\n";
    innerHTML = newHtml;
    scrollLeft = maxValue;
    break;
   default:
    //throw "direction is inccorect!";
    alert("ScrollBar[" + id + "]: direction is incorect!");
    return;
  }

  //set mouse events
  onmouseover = new Function("__scrollBarControl.mouseEvt(" + index + ",true);");
  onmouseout = new Function("__scrollBarControl.mouseEvt(" + index + ",false);");
  if(__firstTime)
  {
   __firstTime=false;
   window.setInterval("__scrollBarControl.scroll(" + index + ");",interval);
  }
  //save maxValue
  this.barsArray[index].maxValue = maxValue;
 }
}
scrollBar.prototype.mouseEvt = function(index, stop)
{
 this.barsArray[index].stopScroll = stop;
}
scrollBar.prototype.scroll = function(index)
{
 //get properties
 var barID = this.barsArray[index].barID;
 var width = this.barsArray[index].width;
 var height = this.barsArray[index].height;
 var interval = this.barsArray[index].interval;
 var direction = this.barsArray[index].direction;
 var stopScroll = this.barsArray[index].stopScroll;
 var preValue = this.barsArray[index].preValue;
 var maxValue = this.barsArray[index].maxValue;

 if ( stopScroll == true ) return;

 switch(direction)
 {
  case "up":
   preValue++;
   if ( preValue >= maxValue )
   {
    preValue = 0;
   }
   barID.scrollTop = preValue;
   break;
  case "down":
   preValue--;
   if ( preValue <= 0 )
   {
    preValue = maxValue;
   }
   barID.scrollTop = preValue;
   break;
  case "left":
   preValue++;
   if ( preValue >= maxValue )
   {
    preValue = 0;
   }
   barID.scrollLeft = preValue;
   break;
  case "right":
   preValue--;
   if ( preValue <=0 )
   {
    preValue = maxValue;
   }
   barID.scrollLeft = preValue;
   break;
 }
 this.barsArray[index].preValue = preValue;
}
//=================end of file===========================
</SCRIPT>
<SCRIPT type="text/javascript">
//這裡是使用在網頁上的
var scrollBarControl = new scrollBar();
MoveTo("up");
function MoveTo(d)
{
 //清除剛才宣告的scrollbarcontrol
 scrollBarControl.clear();
 //新增一欲滾動的ID,五個參數分別為
 //欲滾動的區塊ID,寬,高,速度,方向
 scrollBarControl.addBar("scrollbarDemo", 228, 120, 100, d);
 scrollBarControl.createScrollBars();
}
</SCRIPT>

2007年8月15日 星期三

讓 crontab 自動排程執行 php

前一陣公司的網站改了很多東西...
寫了很多需要利用 crontab 去跑的php
當時利用的方法是
寫一支程式,讓crontab去跑..
內容是

lnyx http://myweb/test.php > /dev/null
2>&2

剛剛在Real-Blog看到這篇文章--讓 crontab 自動排程執行 php

才發現也有這樣的方式可以寫...記錄一下~~

要用 crontab 自動執行 php 程式,可以這樣做:
方法一
1. 在 php 程式的第一行加入:

#!/usr/local/php/bin/php -q
例如:

#!/usr/local/php/bin/php -q
< ? php $foo = 123; ? >
請留意,我的 php 是安裝在 /usr/local/php,請根據你的 php 執行檔位置作出修改。

2. 將 php 程式給予可執行權限:

chmod +x testing.php

3. 執行 crontab -e,然後加入以下內容:

00 00 * * * /path/to/testing.php > /dev/null 2>&2
以上語法會在每天的零時零分執行 /path/to/testing.php

方法二
另一個方法是不用在 php 程式的第一行加入 "#!/usr/local/php/bin/php -q",
可以省略第一步及第二步
直接執行 crontab -e,並輸入以下內容:
00 00 * * * usr/local/php/bin/php -q /path/to/testing.php > /dev/null 2>&2

這個方法的結果跟方法一的結果相同。 前一陣公司的網站改了很多東西...
寫了很多需要利用 crontab 去跑的php
當時利用的方法是
寫一支程式,讓crontab去跑..
內容是

lnyx http://myweb/test.php > /dev/null
2>&2

剛剛在Real-Blog看到這篇文章--讓 crontab 自動排程執行 php

才發現也有這樣的方式可以寫...記錄一下~~

要用 crontab 自動執行 php 程式,可以這樣做:
方法一
1. 在 php 程式的第一行加入:

#!/usr/local/php/bin/php -q
例如:

#!/usr/local/php/bin/php -q
< ? php $foo = 123; ? >
請留意,我的 php 是安裝在 /usr/local/php,請根據你的 php 執行檔位置作出修改。

2. 將 php 程式給予可執行權限:

chmod +x testing.php

3. 執行 crontab -e,然後加入以下內容:

00 00 * * * /path/to/testing.php > /dev/null 2>&2
以上語法會在每天的零時零分執行 /path/to/testing.php

方法二
另一個方法是不用在 php 程式的第一行加入 "#!/usr/local/php/bin/php -q",
可以省略第一步及第二步
直接執行 crontab -e,並輸入以下內容:
00 00 * * * usr/local/php/bin/php -q /path/to/testing.php > /dev/null 2>&2

這個方法的結果跟方法一的結果相同。

2007年8月10日 星期五

清除UTF-8檔的BOM檔頭

今天不小心用Notepad改了個檔案
結果...BOM檔頭就一直存在...拿不掉...
這個怪怪的Bug害我花了很多時間在測試~~
還好有幸看到石頭閒語的這篇文章...
PHP::關於 PHP 4/5 對 UTF-BOM 的 bug

另外有找到移除的小程式...就節錄下來了~~
原文出處:自動移除文件中的 utf-8 bom的小程式
將此檔案擺在根目錄執行便會自動檢查所有檔案....
並自動修正~


<?php
//remove the utf-8 boms
//by magicbug at gmail dot com
if (isset($_GET[’dir’])){ //config the basedir
$basedir=$_GET[’dir’];
}else{
$basedir = ".";
}
$auto = 1;

checkdir($basedir);

function checkdir($basedir){
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != ".."){
if (!is_dir($basedir."/".$file)) {
echo "filename: $basedir/$file ".checkBOM("$basedir/$file")."";
}else{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}

function checkBOM ($filename) {
global $auto;
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return ("BOM found, automatically removed.
");
} else {
return ("BOM found.
");
}
}
else return ("BOM Not Found.
");
}

function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>
今天不小心用Notepad改了個檔案
結果...BOM檔頭就一直存在...拿不掉...
這個怪怪的Bug害我花了很多時間在測試~~
還好有幸看到石頭閒語的這篇文章...
PHP::關於 PHP 4/5 對 UTF-BOM 的 bug

另外有找到移除的小程式...就節錄下來了~~
原文出處:自動移除文件中的 utf-8 bom的小程式
將此檔案擺在根目錄執行便會自動檢查所有檔案....
並自動修正~


<?php
//remove the utf-8 boms
//by magicbug at gmail dot com
if (isset($_GET[’dir’])){ //config the basedir
$basedir=$_GET[’dir’];
}else{
$basedir = ".";
}
$auto = 1;

checkdir($basedir);

function checkdir($basedir){
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != ".."){
if (!is_dir($basedir."/".$file)) {
echo "filename: $basedir/$file ".checkBOM("$basedir/$file")."";
}else{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}

function checkBOM ($filename) {
global $auto;
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return ("BOM found, automatically removed.
");
} else {
return ("BOM found.
");
}
}
else return ("BOM Not Found.
");
}

function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>

2007年8月9日 星期四

投資心法

參考自今周刊 544 期
[資深上班族謝文通 賺遍全世界]



1.選定區域(或國家)
謝文通認為,全世界的熱錢到處流竄,尋找許久未漲且相對便宜的市場去炒作,
即使在空頭時期也是一樣。「這些錢不可躺著半年都不動!」

2.以大盤均線,20日均線,60日均線做比較
大盤跌破 20/60日均線,即逐步出場
相反的,大盤漲破20/60日均線,即逐步進場

待補充..... 參考自今周刊 544 期
[資深上班族謝文通 賺遍全世界]



1.選定區域(或國家)
謝文通認為,全世界的熱錢到處流竄,尋找許久未漲且相對便宜的市場去炒作,
即使在空頭時期也是一樣。「這些錢不可躺著半年都不動!」

2.以大盤均線,20日均線,60日均線做比較
大盤跌破 20/60日均線,即逐步出場
相反的,大盤漲破20/60日均線,即逐步進場

待補充.....

2007年8月7日 星期二

[PHP] 用 "變數" 來指定 變數名稱

$refresh_value="refresh_set1".$no; //用傳入的$no來設定一新字串
if(${$refresh_value}!="") //用上面那一個變數來設定另一個變數名稱
{
 notifyPage('點閱指數更新完成(2)!','f4modify_house_2.php3');
 exit();
}
else
{
 //若該變數不存在,則用此名稱,去設定一個cookie變數!
 setcookie($refresh_value,1,time()+3600*8,"/",$_SERVER['HTTP_POST']);
}

$refresh_value="refresh_set1".$no; //用傳入的$no來設定一新字串
if(${$refresh_value}!="") //用上面那一個變數來設定另一個變數名稱
{
 notifyPage('點閱指數更新完成(2)!','f4modify_house_2.php3');
 exit();
}
else
{
 //若該變數不存在,則用此名稱,去設定一個cookie變數!
 setcookie($refresh_value,1,time()+3600*8,"/",$_SERVER['HTTP_POST']);
}