Wednesday, December 15, 2004

BIG5 字元衝突:: BIG5 string conflict

Big5中由於設計上的疏失,導致一些屬於控制字元的資料容易引起一些程式環境的誤判。造成顯示出來的中文字不是我們想要的結果。所以我們在寫程式的時候對於中文的處理要特別小心。下面列出了一些容易引發衝碼的文字,寫程式的人,最好都能夠測試下面的字在你的程式中可以正確無誤的被使用。

ASCII(5C) == “\”


A45C么 AE5C娉 B85C稞 C25C擺 A55C功

AF5C珮 B95C鈾 C35C黠 A65C吒 B05C豹

BA5C暝 C45C孀 A75C吭 B15C崤 BB5C蓋

C55C髏 A85C沔 B25C淚 BC5C墦 C65C躡

A95C坼 B35C許 BD5C穀 AA5C歿 B45C廄

BE5C閱 AB5C俞 B55C琵 BF5C璞 AC5C枯

B65C跚 C05C餐 AD5C苒 B75C愧 C15C縷


ASCII(7C) == “|”


AA7C泜 B47C揉 A87C育 BE7C魯 B27C琍

BC7C慝 C67C鸛 A97C尚 B37C逖 BD7C罵

A77C坑 B17C悴 BB7C誡 C57C疊 A67C帆

B07C院 BA7C漏 C47C辮 AB7C咽 B57C稅

BF7C糕 AC7C洱 B67C閏 C07C嚐 AD7C迢

B77C會 C17C舉 A47C弋 AE7C徑 B87C腮

C27C甕 A57C四 AF7C砝 B97C頌 C37C牘

"\"

Friday, December 10, 2004

How to run a piece of JavaScript code after a certain timed delay?

This allows you to execute a section of code after a specified amount of time
has passed.


<script type="text/javascript">

<!--

setTimeout("alert('Thirty seconds has passed.');",30000);

// -->

</script>

Allow EZ_Result to display +5Pages link

You can download ez_resuls.php from http://php.justinvincent.com/


Allow EZ_Result to display nav bar like this

365 Results: [start] 1 2 3 4 5 +5Pages [last]


For this to work, I added a few lines to the ez_results.php class as follows


/********************************************************

* NAVIGATION FORMATTING

*/

var $show_next_x_page = true;

var $text_hover_msg_next_x = '+NUMBER Pages';

var $text_next_x_page = '+NUMBER Pages';


In function build_navigation(), I added the following.


$current_page = ($_REQUEST['BRSR'] / $this->num_results_per_page) +1;

$page_left = $this->num_pages-$current_page ;



if($this->show_next_x_page)

if ( ($this->num_pages >= $this->num_browse_links) && (($_REQUEST['BRSR']
+ $this->num_results_per_page) < $this->num_results))

{

if(($page_left * $this->num_results_per_page >= $this->num_results
) || ($current_page * $this->num_results_per_page) < $this->num_results
)

{

if($page_left >= $this->next_x_pages){

$cur_a = $_REQUEST['BRSR'] + $this->num_results_per_page * $this->next_x_pages;

$out .= $this->create_link(preg_replace("/\?.*/",'',$_SERVER['PHP_SELF'])
. '?BRSR='. ($cur_a) .$this->qs,$this->merge_num('next_x_page',$this->next_x_pages),$this->merge_num('hover_msg_next_x',$this->next_x_pages),$this->get_style('next')).'
';

}

else{

$cur_a = $_REQUEST['BRSR'] + $this->num_results_per_page * $page_left;

$out .= $this->create_link(preg_replace("/\?.*/",'',$_SERVER['PHP_SELF'])
. '?BRSR='. ($cur_a) .$this->qs,$this->merge_num('next_x_page',$page_left),$this->merge_num('hover_msg_next_x',$page_left),$this->get_style('next')).'
';

}

}



}

Thursday, December 09, 2004

How do I identify unknown open ports and their associated applications.?

You can go to http://www.foundstone.com
and download Fport. It will show you something like this


FPort v2.0 - TCP/IP Process to Port Mapper

Copyright 2000 by Foundstone, Inc.

http://www.foundstone.com


Pid Process Port Proto Path

1764 inetinfo -> 25 TCP C:\WINDOWS\System32\inetsrv\inetinfo.exe

1764 inetinfo -> 80 TCP C:\WINDOWS\System32\inetsrv\inetinfo.exe

1620 Apache -> 81 TCP C:\Apache\Apache2\bin\Apache.exe

988 -> 135 TCP

4 System -> 139 TCP

1764 inetinfo -> 443 TCP C:\WINDOWS\System32\inetsrv\inetinfo.exe

4 System -> 445 TCP

1764 inetinfo -> 1038 TCP C:\WINDOWS\System32\inetsrv\inetinfo.exe

2536 mqsvc -> 1047 TCP C:\WINDOWS\System32\mqsvc.exe

5632 msnmsgr -> 1056 TCP C:\Program Files\MSN Messenger\msnmsgr.exe

5632 msnmsgr -> 1057 TCP C:\Program Files\MSN Messenger\msnmsgr.exe

5632 msnmsgr -> 1058 TCP C:\Program Files\MSN Messenger\msnmsgr.exe

5632 msnmsgr -> 1059 TCP C:\Program Files\MSN Messenger\msnmsgr.exe

5632 msnmsgr -> 1060 TCP C:\Program Files\MSN Messenger\msnmsgr.exe

3076 -> 1062 TCP

1736 FlashComAdmin -> 1111 TCP C:\Program Files\Macromedia\Flash Communica

tion Server MX\FlashComAdmin.exe

3796 OSDK62http -> 1422 TCP C:\Program Files\Openwave\SDK 6.2.2\program

\http\OSDK62http.exe

5480 firefox -> 1668 TCP C:\Program Files\Mozilla Firefox\firefox.ex

e

5480 firefox -> 1669 TCP C:\Program Files\Mozilla Firefox\firefox.ex

e

2536 mqsvc -> 1801 TCP C:\WINDOWS\System32\mqsvc.exe

2492 FlashCom -> 1935 TCP C:\Program Files\Macromedia\Flash Communica

tion Server MX\FlashCom.exe

2184 omtsreco -> 2030 TCP c:\oracle\ora92\bin\omtsreco.exe

2536 mqsvc -> 2103 TCP C:\WINDOWS\System32\mqsvc.exe

2536 mqsvc -> 2105 TCP C:\WINDOWS\System32\mqsvc.exe

2536 mqsvc -> 2107 TCP C:\WINDOWS\System32\mqsvc.exe

How to open a file as a string from a URL in PHP?

//
// This will read the text file from http://yoursite.com/test.txt

// and store the contents of test.txt into $contents

//


$handle = fopen("http://yoursite.com/test.txt", "rb");

$contents = '';

while (!feof($handle)) {

$contents .= fread($handle, 8192);

}

fclose($handle);

Tuesday, December 07, 2004

WML 怎麼顯示中文?

因為 WML 只接受 UNICODE, 如果你沒有經過 convert, 你就會看到亂碼

下面 mb_convert_encoding($str, "UTF-8", "BIG-5"); 就可以把字串 convert
成 Unicode 啦

<?php

// send wml headers

header("Content-type: text/vnd.wap.wml");

echo "<?xml version=\"1.0\"?>";

echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\""

. " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";

?>

<wml>

<card>

<p>

<?php

$str = "哈囉";

$str = mb_convert_encoding($str, "UTF-8", "BIG-5");

print "<br/>Hello World! $str";

?>

</p>

</card>

</wml>

How to create a Hello World WML script using PHP?

// send wml headers
header("Content-type: text/vnd.wap.wml");
echo "";
echo ". " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
?>



print "
Hello World!";
?>



Saturday, November 27, 2004

How do I schedule the server to generate static HTML files from other dynamic web pages?

Some people would use Perl or PHP to grab data from the database and generate the HTML when the scripts are executed. I'm just too lazy to write another script for a dynamic web page which is already written in languages such as PHP, Perl, ASP, JSP, ColdFusion, etc.


What I do is create a shell script file and utilize OS' pipe function and a text browser to create the HTML file.


For example: create a text file called generate.sh

lynx -source http://someURL.com/yourCode.asp > yourStaticASP.html
lynx -source http://someURL.com/yourCode.php?Var=123 > yourStaticPHP.html

and do a chmod on the file, make sure it is executable, e.g., chmod u+x generate.sh

You may then schedule this script file in your cron table ;-)

How do I use a hyperlink to POST form variable?

How do I use a hyperlink to POST form variable?

<form name="aform" action="somewhere.php" method="post">

<input type="hidden" name="firstName" value=" <?php echo $firstName ; ?> ">

<input type="hidden" name="lastName" value=" <?php echo $lastName ; ?> ">

<input type="hidden" name="section" value="0">

</form>


Simply add a little JavaScript somewhere in the <head> ... </head> part of your page and we're done. The JavaScript would look something like this...



function clickpost(param)

{

document.forms.aform.elements .section.value = param;

document.forms.aform.submit;

return true;

}

Javascript download script

<script language="JavaScript" type="text/javascript">

<!--

function beginDownload() {

idl = -1;

idl = location.search.indexOf("idl=n");

if (idl < 0) document.write('<iframe height="0" width="0"

src="PUT_URL_FOR_DOWNLOAD_FILE_HERE"></iframe>');

}

window.onLoad=beginDownload();

//-->

</script>

Some useful regular expressions...

e-mail (?:(?:\b([_a-z0-9-]+(?:\.[_a
-z0-9-]+)*)@([_a-z0-9-]+(?:\.[_a-z0-9-]+)*)\.(?:[a-z]{2,3})\b))

HTML tag (?:(?:<[^>]+>))
HTML start (?:(?:<[^//][^>]*>))
[HTMLEndTag] (?:(?:]+>))

[QuotedString] (?:(?:[\"](?:(?:[\\][\"])|[^\"]){1,}[\"]))
IP addr
(?:(?:\b([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\b))

Credit Card (?:(?:(\d{3,4})[- ]?(\d{4})[- ]?(\d{4})[- ]?(\d{4})))
HyperLink
(?:(?:(ftp|http|https|telnet|gopher|nntp)://([_a-z\d\-]+(?:\.[_a-z\d\-]+)+)((?:[_a-z\d\-\\\./]+[_a-z\d\-\\/])+)*))

How Do I get row number with SQL commands in MySQL?

Let's suppose we have a table look like this



Name PhoneNumber
-------------- --------------------
Peter        415-895-5689
John         408-854-4587
Louis        408-975-5986


And now I want to issue a SQL command which gives back a row number for each record which would look like this


RowNumber Name PhoneNumber
----------------- -------------------- ---------------------
1   Peter        415-895-5689
2   John         408-854-4587
3   Louis        408-975-5986


Under Oracle, this would be simple task, just issue the following SQL command
SELECT rownum, Name, PhoneNumber from table;
However, MySQL does not offer such convinience as rownum. In MySQL, we need to do the following instead.

mysql> SET @rownum := 0;

mysql> SELECT @rownum := @rownum + 1 AS RowNumber, Name, PhoneNumber from table;

Hope this tip can help you solve your current problem :)