<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>IT Blog &#187; function</title>
	<atom:link href="http://blog.thuongtin.net/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thuongtin.net</link>
	<description>php, sql, autoit, javascript, c, html</description>
	<lastBuildDate>Tue, 15 Sep 2009 00:57:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Chuyển đổi các múi giờ</title>
		<link>http://blog.thuongtin.net/2008/11/18/chuyen-doi-cac-mui-gio/</link>
		<comments>http://blog.thuongtin.net/2008/11/18/chuyen-doi-cac-mui-gio/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 04:06:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=343</guid>
		<description><![CDATA[Converting Between Different Time Zones
&#60;?php
// function to get time
// for another time zone
// given a specific timestamp and hour offset from GMT

function getLocalTime($ts, $offset) {
// performs conversion
// returns UNIX timestamp
return ($ts - date(&#34;Z&#34;, $ts)) + (3600 * $offset);
}
// get current local time in Singapore
// result: &#34;00:11:26 31-10-06 SST&#34;
echo date(&#34;H:i:s d-m-y&#34;, getLocalTime(mktime(), 8)) . &#34; SST ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first"><span style="font-style: italic;">Converting Between Different Time Zones</span></p>
<pre class="brush: php;">&lt;?php
// function to get time
// for another time zone
// given a specific timestamp and hour offset from GMT

function getLocalTime($ts, $offset) {
// performs conversion
// returns UNIX timestamp
return ($ts - date(&quot;Z&quot;, $ts)) + (3600 * $offset);
}
// get current local time in Singapore
// result: &quot;00:11:26 31-10-06 SST&quot;
echo date(&quot;H:i:s d-m-y&quot;, getLocalTime(mktime(), 8)) . &quot; SST \n&quot;;
// get current local time in India
// result: &quot;21:41:26 30-10-06 IST&quot;
echo date(&quot;H:i:s d-m-y&quot;, getLocalTime(mktime(), +5.5)) . &quot; IST \n&quot;;
// get current local time in USA (Eastern)
// result: &quot;11:11:26 30-10-06 EST&quot;
echo date(&quot;H:i:s d-m-y&quot;, getLocalTime(mktime(), -5)) . &quot; EST \n&quot;;
// get current local time in USA (Pacific)
// result: &quot;08:11:26 30-10-06 PST&quot;
echo date(&quot;H:i:s d-m-y&quot;, getLocalTime(mktime(), -8)) . &quot; PST \n&quot;;
// get time in GMT
// when it is 04:30 AM in India
// result: &quot;23:00:00 01-02-05 GMT &quot;
echo date(&quot;H:i:s d-m-y&quot;, getLocalTime(mktime(4,30,0,2,2,2005), 0)) .?
&quot; GMT \n&quot;;
?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/11/18/so-sanh-2-ngay/" rel="bookmark">So sánh 2 ngày</a></li><li><a href="http://blog.thuongtin.net/2008/10/29/so-sanh-2-ngay-comparing-dates/" rel="bookmark">So sánh 2 ngày - Comparing Dates</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/tao-1-file-download-file/" rel="bookmark">Tạo 1 file download file</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/class-login/" rel="bookmark">Class login</a></li><li><a href="http://blog.thuongtin.net/2008/10/29/chuyen-doi-phut-sang-gio-va-nguoc-lai/" rel="bookmark">Chuyển đổi phút sang giờ và ngược lại</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=343&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/18/chuyen-doi-cac-mui-gio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chuyển đổi phút sang giờ và ngược lại</title>
		<link>http://blog.thuongtin.net/2008/11/18/chuyen-doi-phut-sang-gio-va-nguoc-lai-2/</link>
		<comments>http://blog.thuongtin.net/2008/11/18/chuyen-doi-phut-sang-gio-va-nguoc-lai-2/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 04:00:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=340</guid>
		<description><![CDATA[Converting Minutes to Hours
Phút qua giờ:

&#60;?php
// define number of minutes
$mm = 156;
// convert to hh:mm format
// result: &#34;02h 36m&#34;
echo sprintf(&#34;%02dh %02dm&#34;, floor($mm/60), $mm%60);
?&#62;

Ngược lại:

&#60;?php
// define hours and minutes
$hhmm = &#34;02:36&#34;;
// convert to minutes
// result: &#34;156 minutes&#34;
$arr = explode(&#34;:&#34;, $hhmm);
echo $arr[0]*60 + $arr[1] . &#34; minutes&#34;;
?&#62;

Related Posts:Chuyển đổi phút sang giờ và ngược lạiPHP Function to ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first"><span style="font-style: italic;">Converting Minutes to Hours</span></p>
<p><strong>Phút qua giờ</strong>:</p>
<pre class="brush: php;">
&lt;?php
// define number of minutes
$mm = 156;
// convert to hh:mm format
// result: &quot;02h 36m&quot;
echo sprintf(&quot;%02dh %02dm&quot;, floor($mm/60), $mm%60);
?&gt;
</pre>
<p><strong>Ngược lại:</strong></p>
<pre class="brush: php;">
&lt;?php
// define hours and minutes
$hhmm = &quot;02:36&quot;;
// convert to minutes
// result: &quot;156 minutes&quot;
$arr = explode(&quot;:&quot;, $hhmm);
echo $arr[0]*60 + $arr[1] . &quot; minutes&quot;;
?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/10/29/chuyen-doi-phut-sang-gio-va-nguoc-lai/" rel="bookmark">Chuyển đổi phút sang giờ và ngược lại</a></li><li><a href="http://blog.thuongtin.net/2008/11/04/php-function-to-calculate-time-remaining/" rel="bookmark">PHP Function to calculate time remaining</a></li><li><a href="http://blog.thuongtin.net/2008/11/18/chuyen-doi-cac-mui-gio/" rel="bookmark">Chuyển đổi các múi giờ</a></li><li><a href="http://blog.thuongtin.net/2008/10/18/8-mau-regular-expressions-huu-ich/" rel="bookmark">8 mẫu Regular Expressions hữu ích</a></li><li><a href="http://blog.thuongtin.net/2008/09/11/mot-so-cach-xu-ly-chuoi/" rel="bookmark">Một số cách xử lý chuỗi</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=340&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/18/chuyen-doi-phut-sang-gio-va-nguoc-lai-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>So sánh 2 ngày</title>
		<link>http://blog.thuongtin.net/2008/11/18/so-sanh-2-ngay/</link>
		<comments>http://blog.thuongtin.net/2008/11/18/so-sanh-2-ngay/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 03:58:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=338</guid>
		<description><![CDATA[Comparing Dates

&#60;?php
// create timestamps for two dates
$date1 = mktime(0,0,0,2,1,2007);
$date2 = mktime(1,0,0,2,1,2007);
// compare timestamps
// to see which represents an earlier date
if ($date1 &#62; $date2) {
$str = date (&#34;d-M-Y H:i:s&#34;, $date2) . &#34; comes before &#34; .?
date (&#34;d-M-Y H:i:s&#34;, $date1);
} else if ($date2 &#62; $date1) {
$str = date (&#34;d-M-Y H:i:s&#34;, $date1) . &#34; comes before &#34; .?
date ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first"><span style="font-style: italic;">Comparing Dates</span></p>
<pre class="brush: php;">
&lt;?php
// create timestamps for two dates
$date1 = mktime(0,0,0,2,1,2007);
$date2 = mktime(1,0,0,2,1,2007);
// compare timestamps
// to see which represents an earlier date
if ($date1 &gt; $date2) {
$str = date (&quot;d-M-Y H:i:s&quot;, $date2) . &quot; comes before &quot; .?
date (&quot;d-M-Y H:i:s&quot;, $date1);
} else if ($date2 &gt; $date1) {
$str = date (&quot;d-M-Y H:i:s&quot;, $date1) . &quot; comes before &quot; .?
date (&quot;d-M-Y H:i:s&quot;, $date2);
} else {
$str = &quot;Dates are equal&quot;;
}
// result: &quot;01-Feb-2007 00:00:00 comes before 01-Feb-2007 01:00:00&quot;
echo $str;
?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/10/29/so-sanh-2-ngay-comparing-dates/" rel="bookmark">So sánh 2 ngày - Comparing Dates</a></li><li><a href="http://blog.thuongtin.net/2008/11/18/chuyen-doi-cac-mui-gio/" rel="bookmark">Chuyển đổi các múi giờ</a></li><li><a href="http://blog.thuongtin.net/2008/10/18/8-mau-regular-expressions-huu-ich/" rel="bookmark">8 mẫu Regular Expressions hữu ích</a></li><li><a href="http://blog.thuongtin.net/2008/09/09/gui-email-dang-html-voi-ham-mail/" rel="bookmark">Gửi email dạng HTML với hàm mail()</a></li><li><a href="http://blog.thuongtin.net/2008/09/10/class-curl/" rel="bookmark">Class Curl</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=338&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/18/so-sanh-2-ngay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Tính Can Chi</title>
		<link>http://blog.thuongtin.net/2008/11/05/php-tinh-can-chi/</link>
		<comments>http://blog.thuongtin.net/2008/11/05/php-tinh-can-chi/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 08:02:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[can chi]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=311</guid>
		<description><![CDATA[Xác định 1 năm can chi là gì, cái này tớ chuyển từ C qua 
Đây là hàm php đã chuyển:

&#60;?php
function canchi($nam)
{
$acan = array(&#34;Giap&#34;, &#34;At&#34;, &#34;Binh&#34;, &#34;Dinh&#34;, &#34;Mau&#34;, &#34;Ky&#34;, &#34;Canh&#34;, &#34;Tan&#34;, &#34;Nham&#34;, &#34;Quy&#34;);
$achi = array(&#34;Ty&#34;, &#34;Suu&#34;, &#34;Dan&#34;, &#34;Meo&#34;, &#34;Thin&#34;, &#34;Ty&#34;, &#34;Ngo&#34;, &#34;Mao&#34;, &#34;Than&#34;, &#34;Dau&#34;, &#34;Tuat&#34;, &#34;Hoi&#34;);
$can = $acan[($nam+6)%10];
$chi = $achi[($nam+8)%12];
return $can.&#34; &#34;.$chi;
}
echo canchi(1988);
?&#62;

Còn đây là ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Xác định 1 năm can chi là gì, cái này tớ chuyển từ C qua <img src='http://blog.thuongtin.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
Đây là hàm php đã chuyển:</p>
<pre class="brush: php;">
&lt;?php
function canchi($nam)
{
$acan = array(&quot;Giap&quot;, &quot;At&quot;, &quot;Binh&quot;, &quot;Dinh&quot;, &quot;Mau&quot;, &quot;Ky&quot;, &quot;Canh&quot;, &quot;Tan&quot;, &quot;Nham&quot;, &quot;Quy&quot;);
$achi = array(&quot;Ty&quot;, &quot;Suu&quot;, &quot;Dan&quot;, &quot;Meo&quot;, &quot;Thin&quot;, &quot;Ty&quot;, &quot;Ngo&quot;, &quot;Mao&quot;, &quot;Than&quot;, &quot;Dau&quot;, &quot;Tuat&quot;, &quot;Hoi&quot;);
$can = $acan[($nam+6)%10];
$chi = $achi[($nam+8)%12];
return $can.&quot; &quot;.$chi;
}
echo canchi(1988);
?&gt;
</pre>
<p>Còn đây là C:</p>
<pre class="brush: cpp;">#include &lt;stdio.h&gt;
#include &lt;conio.h&gt;
void main()
{
unsigned nam;
char can[][5] = {&quot;Giap&quot;, &quot;At&quot;, &quot;Binh&quot;, &quot;Dinh&quot;, &quot;Mau&quot;, &quot;Ky&quot;,
&quot;Canh&quot;, &quot;Tan&quot;, &quot;Nham&quot;, &quot;Quy&quot;};
char chi[][5] = {&quot;Ty&quot;, &quot;Suu&quot;, &quot;Dan&quot;, &quot;Meo&quot;, &quot;Thin&quot;, &quot;Ty&quot;,
&quot;Ngo&quot;, &quot;Mao&quot;, &quot;Than&quot;, &quot;Dau&quot;, &quot;Tuat&quot;, &quot;Hoi&quot;};

printf(&quot;\nNhap nam can biet : &quot;);
scanf(&quot;%d&quot;, &amp;amp;amp;nam);
printf(&quot;Nam am lich cua %d la %s %s\n\n&quot;, nam, can[(nam+6)%10], chi[(nam+8)%12]);
getch();
}
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/11/05/may-tinh-don-gian-bang-c/" rel="bookmark">Máy tính đơn giản bằng C</a></li><li><a href="http://blog.thuongtin.net/2008/11/04/chuyen-so-thanh-so-la-ma/" rel="bookmark">Chuyển số thành số La Mã</a></li><li><a href="http://blog.thuongtin.net/2008/09/09/loc-dau-tieng-viet/" rel="bookmark">Lọc dấu tiếng Việt</a></li><li><a href="http://blog.thuongtin.net/2008/10/10/ham-tinh-tuoi/" rel="bookmark">Hàm tính tuổi</a></li><li><a href="http://blog.thuongtin.net/2008/11/03/lap-trinh-huong-doi-tuong-can-ban/" rel="bookmark">Lập trình hướng đối tượng căn bản</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=311&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/05/php-tinh-can-chi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Function to calculate time remaining</title>
		<link>http://blog.thuongtin.net/2008/11/04/php-function-to-calculate-time-remaining/</link>
		<comments>http://blog.thuongtin.net/2008/11/04/php-function-to-calculate-time-remaining/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 04:03:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=306</guid>
		<description><![CDATA[PHP Function to calculate time remaining.
//FUNCTION FOR TIME LEFT
function time_left($integer)
{

$seconds=$integer;

if ($seconds/60 &#62;=1)

{

$minutes=floor($seconds/60);

if ($minutes/60 &#62;= 1)

{ # Hours

$hours=floor($minutes/60);

if ($hours/24 &#62;= 1)

{ #days

$days=floor($hours/24);

if ($days/7 &#62;=1)

{ #weeks

$weeks=floor($days/7);

if ($weeks&#62;=2) $return=&#34;$weeks Weeks&#34;;

else $return=&#34;$weeks Week&#34;;

} #end of weeks

$days=$days-(floor($days/7))*7;

if ($weeks&#62;=1 &#38;&#38; $days &#62;=1) $return=&#34;$return, &#34;;

if ($days &#62;=2) $return=&#34;$return $days days&#34;;

if ($days ==1) $return=&#34;$return $days day&#34;;

} #end of days

$hours=$hours-(floor($hours/24))*24;

if ($days&#62;=1 &#38;&#38; $hours &#62;=1) ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">PHP Function to calculate time remaining.</p>
<pre class="brush: php;">//FUNCTION FOR TIME LEFT
function time_left($integer)
{

$seconds=$integer;

if ($seconds/60 &gt;=1)

{

$minutes=floor($seconds/60);

if ($minutes/60 &gt;= 1)

{ # Hours

$hours=floor($minutes/60);

if ($hours/24 &gt;= 1)

{ #days

$days=floor($hours/24);

if ($days/7 &gt;=1)

{ #weeks

$weeks=floor($days/7);

if ($weeks&gt;=2) $return=&quot;$weeks Weeks&quot;;

else $return=&quot;$weeks Week&quot;;

} #end of weeks

$days=$days-(floor($days/7))*7;

if ($weeks&gt;=1 &amp;&amp; $days &gt;=1) $return=&quot;$return, &quot;;

if ($days &gt;=2) $return=&quot;$return $days days&quot;;

if ($days ==1) $return=&quot;$return $days day&quot;;

} #end of days

$hours=$hours-(floor($hours/24))*24;

if ($days&gt;=1 &amp;&amp; $hours &gt;=1) $return=&quot;$return, &quot;;

if ($hours &gt;=2) $return=&quot;$return $hours hours&quot;;

if ($hours ==1) $return=&quot;$return $hours hour&quot;;

} #end of Hours

$minutes=$minutes-(floor($minutes/60))*60;

if ($hours&gt;=1 &amp;&amp; $minutes &gt;=1) $return=&quot;$return, &quot;;

if ($minutes &gt;=2) $return=&quot;$return $minutes minutes&quot;;

if ($minutes ==1) $return=&quot;$return $minutes minute&quot;;

} #end of minutes

$seconds=$integer-(floor($integer/60))*60;

if ($minutes&gt;=1 &amp;&amp; $seconds &gt;=1) $return=&quot;$return, &quot;;

if ($seconds &gt;=2) $return=&quot;$return $seconds seconds&quot;;

if ($seconds ==1) $return=&quot;$return $seconds second&quot;;

$return=&quot;$return.&quot;;

return $return;

}

/* Returns a string of the amount of time the integer (in seconds) refers
to.

$timeleft=time_left(86400);

$timeleft='1 day'.

Will not return anything higher than weeks. False if $integer=0 or fails.

*/
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/10/29/chuyen-doi-phut-sang-gio-va-nguoc-lai/" rel="bookmark">Chuyển đổi phút sang giờ và ngược lại</a></li><li><a href="http://blog.thuongtin.net/2008/11/18/chuyen-doi-phut-sang-gio-va-nguoc-lai-2/" rel="bookmark">Chuyển đổi phút sang giờ và ngược lại</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/lay-thoi-gian-cua-tap-tin-flv/" rel="bookmark">Lấy thời gian của tập tin .flv</a></li><li><a href="http://blog.thuongtin.net/2008/11/04/chuyen-so-thanh-so-la-ma/" rel="bookmark">Chuyển số thành số La Mã</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/file-sao-luu-du-lieu/" rel="bookmark">File sao lưu dữ liệu</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=306&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/04/php-function-to-calculate-time-remaining/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Morse Code encoder/decoder</title>
		<link>http://blog.thuongtin.net/2008/11/04/morse-code-encoderdecoder/</link>
		<comments>http://blog.thuongtin.net/2008/11/04/morse-code-encoderdecoder/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 04:01:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[converter]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[morse]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=304</guid>
		<description><![CDATA[Morse Code encoder/decoder
$lettertomorse=array(
&#34;a&#34; =&#62; &#34;.-&#34;,
&#34;b&#34; =&#62; &#34;-...&#34;,
&#34;c&#34; =&#62; &#34;-.-.&#34;,
&#34;d&#34; =&#62; &#34;-..&#34;,
&#34;e&#34; =&#62; &#34;.&#34;,
&#34;f&#34; =&#62; &#34;..-.&#34;,
&#34;g&#34; =&#62; &#34;--.&#34;,
&#34;h&#34; =&#62; &#34;....&#34;,
&#34;i&#34; =&#62; &#34;..&#34;,
&#34;j&#34; =&#62; &#34;.---&#34;,
&#34;k&#34; =&#62; &#34;.-.&#34;,
&#34;l&#34; =&#62; &#34;.-..&#34;,
&#34;m&#34; =&#62; &#34;--&#34;,
&#34;n&#34; =&#62; &#34;-.&#34;,
&#34;o&#34; =&#62; &#34;---&#34;,
&#34;p&#34; =&#62; &#34;.--.&#34;,
&#34;q&#34; =&#62; &#34;--.-&#34;,
&#34;r&#34; =&#62; &#34;.-.&#34;,
&#34;s&#34; =&#62; &#34;...&#34;,
&#34;t&#34; =&#62; &#34;-&#34;,
&#34;u&#34; =&#62; &#34;..-&#34;,
&#34;v&#34; =&#62; &#34;...-&#34;,
&#34;w&#34; =&#62; &#34;.--&#34;,
&#34;x&#34; =&#62; &#34;-..-&#34;,
&#34;y&#34; =&#62; &#34;-.--&#34;,
&#34;z&#34; =&#62; &#34;--..&#34;,
&#34;1&#34; ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Morse Code encoder/decoder</p>
<pre class="brush: php;">$lettertomorse=array(
&quot;a&quot; =&gt; &quot;.-&quot;,
&quot;b&quot; =&gt; &quot;-...&quot;,
&quot;c&quot; =&gt; &quot;-.-.&quot;,
&quot;d&quot; =&gt; &quot;-..&quot;,
&quot;e&quot; =&gt; &quot;.&quot;,
&quot;f&quot; =&gt; &quot;..-.&quot;,
&quot;g&quot; =&gt; &quot;--.&quot;,
&quot;h&quot; =&gt; &quot;....&quot;,
&quot;i&quot; =&gt; &quot;..&quot;,
&quot;j&quot; =&gt; &quot;.---&quot;,
&quot;k&quot; =&gt; &quot;.-.&quot;,
&quot;l&quot; =&gt; &quot;.-..&quot;,
&quot;m&quot; =&gt; &quot;--&quot;,
&quot;n&quot; =&gt; &quot;-.&quot;,
&quot;o&quot; =&gt; &quot;---&quot;,
&quot;p&quot; =&gt; &quot;.--.&quot;,
&quot;q&quot; =&gt; &quot;--.-&quot;,
&quot;r&quot; =&gt; &quot;.-.&quot;,
&quot;s&quot; =&gt; &quot;...&quot;,
&quot;t&quot; =&gt; &quot;-&quot;,
&quot;u&quot; =&gt; &quot;..-&quot;,
&quot;v&quot; =&gt; &quot;...-&quot;,
&quot;w&quot; =&gt; &quot;.--&quot;,
&quot;x&quot; =&gt; &quot;-..-&quot;,
&quot;y&quot; =&gt; &quot;-.--&quot;,
&quot;z&quot; =&gt; &quot;--..&quot;,
&quot;1&quot; =&gt; &quot;.----&quot;,
&quot;2&quot; =&gt; &quot;..---&quot;,
&quot;3&quot; =&gt; &quot;...--&quot;,
&quot;4&quot; =&gt; &quot;....-&quot;,
&quot;5&quot; =&gt; &quot;.....&quot;,
&quot;6&quot; =&gt; &quot;-....&quot;,
&quot;7&quot; =&gt; &quot;--...&quot;,
&quot;8&quot; =&gt; &quot;---..&quot;,
&quot;9&quot; =&gt; &quot;----.&quot;,
&quot;0&quot; =&gt; &quot;-----&quot;,
&quot; &quot; =&gt; &quot;   &quot;,
&quot;.&quot; =&gt; &quot;.-.-.-&quot;,
&quot;,&quot; =&gt; &quot;--..--&quot;,
&quot;EOM&quot; =&gt; &quot;.-.-.&quot;
);

$morsetoletter=array();
reset($lettertomorse);
foreach($lettertomorse as $letter =&gt; $code)
{
$morsetoletter[$code]=$letter;
}

function morse_encode($txt)
{
global $lettertomorse;

$line=&quot;&quot;;
for ($i=0;$i&lt;strlen($txt);$i++)
{
$letter=substr($txt,$i,1);

// ignore unknown characters
if (empty($lettertomorse[$letter]))
continue;

$line.=$lettertomorse[$letter].&quot; &quot;;
}
return $line;
}

function morse_decode($string)
{
global $morsetoletter;

$line=&quot;&quot;;
$letters=array();
$letters=explode(&quot; &quot;,$string);
foreach ($letters as $letter)
{
// ignore unknown characters
if (empty($letter))
$line.=&quot; &quot;;
if (empty($morsetoletter[$letter]))
continue;

$line.=$morsetoletter[$letter];
}
return $line;
}
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/10/15/lay-noi-dung-cua-1-trang-web-file_get_contents/" rel="bookmark">Lấy nội dung của 1 trang web = file_get_contents</a></li><li><a href="http://blog.thuongtin.net/2008/09/09/loc-dau-tieng-viet/" rel="bookmark">Lọc dấu tiếng Việt</a></li><li><a href="http://blog.thuongtin.net/2009/04/21/14-loi-khuyen-cua-ong-iec-haramis/" rel="bookmark">14 lời khuyên của ông I.E.C. Haramis</a></li><li><a href="http://blog.thuongtin.net/2009/04/21/cach-su-dung-lenh-dung-lo/" rel="bookmark">Cách sử dụng lệnh dừng lỗ</a></li><li><a href="http://blog.thuongtin.net/2008/10/29/ngau-nhien/" rel="bookmark">Ngẫu Nhiên</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=304&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/04/morse-code-encoderdecoder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chuyển số thành số La Mã</title>
		<link>http://blog.thuongtin.net/2008/11/04/chuyen-so-thanh-so-la-ma/</link>
		<comments>http://blog.thuongtin.net/2008/11/04/chuyen-so-thanh-so-la-ma/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 03:57:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[Roman]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=302</guid>
		<description><![CDATA[Chuyển số thành số La Mã.
Chắc mọi người đều biết về số la mã: I, II, III, IV, V, VI, VII, VIII, IX, X&#8230;.
Và&#8230;
 M = 1,000
 C = 100
 X = 10
 I = 1
 D = 500
 L = 50
 V = 5
Đây là hàm chuyển số thành số La Mã:

// A function ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Chuyển số thành số La Mã.</p>
<p>Chắc mọi người đều biết về số la mã: I, II, III, IV, V, VI, VII, VIII, IX, X&#8230;.<br />
Và&#8230;</p>
<pre class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 600px; height: 130px;"> M = 1,000
 C = 100
 X = 10
 I = 1
 D = 500
 L = 50
 V = 5</pre>
<p>Đây là hàm chuyển số thành số La Mã:</p>
<pre class="brush: php;">
// A function to return the Roman Numeral, given an integer
function numberToRoman($num)
{
// Make sure that we only use the integer portion of the value
$n = intval($num);
$result = '';

// Declare a lookup array that we will use to traverse the number:
$lookup = array('M' =&gt; 1000, 'CM' =&gt; 900, 'D' =&gt; 500, 'CD' =&gt; 400,
'C' =&gt; 100, 'XC' =&gt; 90, 'L' =&gt; 50, 'XL' =&gt; 40,
'X' =&gt; 10, 'IX' =&gt; 9, 'V' =&gt; 5, 'IV' =&gt; 4, 'I' =&gt; 1);

foreach ($lookup as $roman =&gt; $value)
{
// Determine the number of matches
$matches = intval($n / $value);

// Store that many characters
$result .= str_repeat($roman, $matches);

// Substract that from the number
$n = $n % $value;
}

// The Roman numeral should be built, return it
return $result;
}
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/09/12/file-sao-luu-du-lieu/" rel="bookmark">File sao lưu dữ liệu</a></li><li><a href="http://blog.thuongtin.net/2008/10/15/lay-noi-dung-cua-1-trang-web-file_get_contents/" rel="bookmark">Lấy nội dung của 1 trang web = file_get_contents</a></li><li><a href="http://blog.thuongtin.net/2008/10/10/chong-view-link-tu-cac-site-xai-xtre/" rel="bookmark">Chống view link từ các site xài xtre</a></li><li><a href="http://blog.thuongtin.net/2008/11/18/chuyen-doi-cac-mui-gio/" rel="bookmark">Chuyển đổi các múi giờ</a></li><li><a href="http://blog.thuongtin.net/2008/10/29/chuyen-doi-phut-sang-gio-va-nguoc-lai/" rel="bookmark">Chuyển đổi phút sang giờ và ngược lại</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=302&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/11/04/chuyen-so-thanh-so-la-ma/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chuyển đổi phút sang giờ và ngược lại</title>
		<link>http://blog.thuongtin.net/2008/10/29/chuyen-doi-phut-sang-gio-va-nguoc-lai/</link>
		<comments>http://blog.thuongtin.net/2008/10/29/chuyen-doi-phut-sang-gio-va-nguoc-lai/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 08:51:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=258</guid>
		<description><![CDATA[Converting Minutes to Hours
Phút sang giờ:

&#60;?php
// define number of minutes
$mm = 156;
// convert to hh:mm format
// result: &#34;02h 36m&#34;
echo sprintf(&#34;%02dh %02dm&#34;, floor($mm/60), $mm%60);
?&#62;

Và phút sang giờ:

&#60;?php
// define hours and minutes
$hhmm = &#34;02:36&#34;;
// convert to minutes
// result: &#34;156 minutes&#34;
$arr = explode(&#34;:&#34;, $hhmm);
echo $arr[0]*60 + $arr[1] . &#34; minutes&#34;;
?&#62;

Related Posts:Chuyển đổi phút sang giờ và ngược lạiPHP ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first"><span style="font-style: italic;">Converting Minutes to Hours</span></p>
<p>Phút sang giờ:</p>
<pre class="brush: php;">
&lt;?php
// define number of minutes
$mm = 156;
// convert to hh:mm format
// result: &quot;02h 36m&quot;
echo sprintf(&quot;%02dh %02dm&quot;, floor($mm/60), $mm%60);
?&gt;
</pre>
<p>Và phút sang giờ:</p>
<pre class="brush: php;">
&lt;?php
// define hours and minutes
$hhmm = &quot;02:36&quot;;
// convert to minutes
// result: &quot;156 minutes&quot;
$arr = explode(&quot;:&quot;, $hhmm);
echo $arr[0]*60 + $arr[1] . &quot; minutes&quot;;
?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/11/18/chuyen-doi-phut-sang-gio-va-nguoc-lai-2/" rel="bookmark">Chuyển đổi phút sang giờ và ngược lại</a></li><li><a href="http://blog.thuongtin.net/2008/11/04/php-function-to-calculate-time-remaining/" rel="bookmark">PHP Function to calculate time remaining</a></li><li><a href="http://blog.thuongtin.net/2008/11/18/chuyen-doi-cac-mui-gio/" rel="bookmark">Chuyển đổi các múi giờ</a></li><li><a href="http://blog.thuongtin.net/2008/11/04/chuyen-so-thanh-so-la-ma/" rel="bookmark">Chuyển số thành số La Mã</a></li><li><a href="http://blog.thuongtin.net/2008/11/18/so-sanh-2-ngay/" rel="bookmark">So sánh 2 ngày</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=258&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/10/29/chuyen-doi-phut-sang-gio-va-nguoc-lai/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>So sánh 2 ngày &#8211; Comparing Dates</title>
		<link>http://blog.thuongtin.net/2008/10/29/so-sanh-2-ngay-comparing-dates/</link>
		<comments>http://blog.thuongtin.net/2008/10/29/so-sanh-2-ngay-comparing-dates/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 08:48:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=255</guid>
		<description><![CDATA[

&#60;?php
// create timestamps for two dates
$date1 = mktime(0,0,0,2,1,2007);
$date2 = mktime(1,0,0,2,1,2007);
// compare timestamps
// to see which represents an earlier date
if ($date1 &#62; $date2) {
$str = date (&#34;d-M-Y H:i:s&#34;, $date2) . &#34; comes before &#34; .?
date (&#34;d-M-Y H:i:s&#34;, $date1);
} else if ($date2 &#62; $date1) {
$str = date (&#34;d-M-Y H:i:s&#34;, $date1) . &#34; comes before &#34; .?
date (&#34;d-M-Y ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">
<pre class="brush: php;">
&lt;?php
// create timestamps for two dates
$date1 = mktime(0,0,0,2,1,2007);
$date2 = mktime(1,0,0,2,1,2007);
// compare timestamps
// to see which represents an earlier date
if ($date1 &gt; $date2) {
$str = date (&quot;d-M-Y H:i:s&quot;, $date2) . &quot; comes before &quot; .?
date (&quot;d-M-Y H:i:s&quot;, $date1);
} else if ($date2 &gt; $date1) {
$str = date (&quot;d-M-Y H:i:s&quot;, $date1) . &quot; comes before &quot; .?
date (&quot;d-M-Y H:i:s&quot;, $date2);
} else {
$str = &quot;Dates are equal&quot;;
}
// result: &quot;01-Feb-2007 00:00:00 comes before 01-Feb-2007 01:00:00&quot;
echo $str;
?&gt;
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/11/18/so-sanh-2-ngay/" rel="bookmark">So sánh 2 ngày</a></li><li><a href="http://blog.thuongtin.net/2008/11/18/chuyen-doi-cac-mui-gio/" rel="bookmark">Chuyển đổi các múi giờ</a></li><li><a href="http://blog.thuongtin.net/2008/09/09/gui-email-dang-html-voi-ham-mail/" rel="bookmark">Gửi email dạng HTML với hàm mail()</a></li><li><a href="http://blog.thuongtin.net/2008/10/07/12-javascript-image-galleries/" rel="bookmark">12 Javascript Image Galleries</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/tao-1-file-download-file/" rel="bookmark">Tạo 1 file download file</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=255&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/10/29/so-sanh-2-ngay-comparing-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ngẫu Nhiên</title>
		<link>http://blog.thuongtin.net/2008/10/29/ngau-nhien/</link>
		<comments>http://blog.thuongtin.net/2008/10/29/ngau-nhien/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 02:46:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://thuongtin.net/blog/?p=250</guid>
		<description><![CDATA[Số ngẫu nhiên:

function get_random_number($min = 0, $max = 100)
{
return rand($min,$max);
}

Chuỗi ngẫu nhiên từ 1 mảng:

function get_random_string_from_list($list_of_words)
{
return $list_of_words[rand(0,sizeof($list_of_words)-1)];
}

Chuỗi ngẫu nhiên:

function get_random_string($length=6,$characters = &#34;ABCDEFGHIJKLMNOPRQSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_&#34;)
{
$num_characters = strlen($characters) - 1;
while (strlen($return) &#60; $length)
{
$return.= $characters[mt_rand(0,$num_characters)];
}
return $return;
}

Số float ngẫu nhiên:

function random_float ($min,$max)
{
return ($min + lcg_value() * (abs($max-$min)));
}

Hex Color ngẫu nhiên:

function get_random_hex_color($values = 'abcdef0123456789',$length=6)
{
$num_characters = strlen($characters) - 1;
while (strlen($code) &#60; $length)
{
$return.= $characters[mt_rand(0,$num_characters)];
}
return ]]></description>
			<content:encoded><![CDATA[<p class="dropcap-first">Số ngẫu nhiên:</p>
<pre class="brush: php;">
function get_random_number($min = 0, $max = 100)
{
return rand($min,$max);
}
</pre>
<p>Chuỗi ngẫu nhiên từ 1 mảng:</p>
<pre class="brush: php;">
function get_random_string_from_list($list_of_words)
{
return $list_of_words[rand(0,sizeof($list_of_words)-1)];
}
</pre>
<p>Chuỗi ngẫu nhiên:</p>
<pre class="brush: php;">
function get_random_string($length=6,$characters = &quot;ABCDEFGHIJKLMNOPRQSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_&quot;)
{
$num_characters = strlen($characters) - 1;
while (strlen($return) &lt; $length)
{
$return.= $characters[mt_rand(0,$num_characters)];
}
return $return;
}
</pre>
<p>Số float ngẫu nhiên:</p>
<pre class="brush: php;">
function random_float ($min,$max)
{
return ($min + lcg_value() * (abs($max-$min)));
}
</pre>
<p>Hex Color ngẫu nhiên:</p>
<pre class="brush: php;">
function get_random_hex_color($values = 'abcdef0123456789',$length=6)
{
$num_characters = strlen($characters) - 1;
while (strlen($code) &lt; $length)
{
$return.= $characters[mt_rand(0,$num_characters)];
}
return '#'.$return;
}
</pre>
<p>File ngẫu nhiên từ một thư mục:</p>
<pre class="brush: php;">
function get_random_file($dir)
{
while (false !== ($file = readdir($dir)))
{
$files[] = $file;
}
return $files[rand(0,sizeof($files)-1)];
}
</pre>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.thuongtin.net/2008/09/11/ham-kiem-tra-file-size/" rel="bookmark">Hàm kiểm tra file size</a></li><li><a href="http://blog.thuongtin.net/2008/09/13/scan-for-images/" rel="bookmark">Scan for Images</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/chay-ngau-nhien-1-video-flash-trong-thu-muc/" rel="bookmark">Chạy ngẫu nhiên 1 video flash trong thư mục</a></li><li><a href="http://blog.thuongtin.net/2008/09/12/lay-thoi-gian-cua-tap-tin-flv/" rel="bookmark">Lấy thời gian của tập tin .flv</a></li><li><a href="http://blog.thuongtin.net/2008/11/04/morse-code-encoderdecoder/" rel="bookmark">Morse Code encoder/decoder</a></li></ul></div><img src="http://blog.thuongtin.net/?ak_action=api_record_view&id=250&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://blog.thuongtin.net/2008/10/29/ngau-nhien/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
