php

encoding

in

บังเอิญได้รับงานเขียนเว็บเล็กๆมางานนึง (เล็กมากๆ) ความต้องการคร่าวๆคือมีข้อมูลบนฐานข้อมูล เอาขึ้นมาแสดงบนเว็บตามต้องการ เื่องด้วยปัจจัยหลายๆอย่างก็เลยเลือกใช้ PHP กับ MySQL

จริงๆแล้วก่อนที่จะหัดใช้ ASP.NET ก็เคยเขียน PHP มาอยู่ก่อนแล้ว ยิ่งช่วงหลังก็ได้กลับมาลองเล่นอยู่เนืองๆก็เลยไม่ค่อยเจอปัญหาเท่าไหร่ แต่ก็มีที่เจอคือเรื่ื่อง encoding นี่แหละ

time

in

In PHP, both mktime and gmtime yield the same unix_timestamp with no argument passed.

<?php

echo mktime() == gmmktime() ? 'eq' : ' not eq';

?>

yields 'eq'

However, mktime argument is "local time" but the gmmktime’s is "GMT time".

<?php

echo Date("D M Y H:i:s e", mktime(0,0,7,10,12,2007) );
echo '<br/>';
echo Date("D M Y H:i:s e", gmmktime(0,0,7,10,12,2007) );
?>

yields

Fri Oct 2007 00:00:07 Asia/Krasnoyarsk
Fri Oct 2007 08:00:07 Asia/Krasnoyarsk

Let’s compare this to .NET.

In .NET, class DateTime has responsibility to these kind of task. In fact, DateTime class has one static property to get current, local time (or day), DateTime.Now, and another property, DateTime.UtcNow, provides current universal time.  To calculate time, Timespan struct comes into play but I usually use various method on DateTime object to do so. Moreover, universal time is advised to use in time calculation.

DateTime d = DateTime.Now // get current local time
DateTime u = d.ToUniversalTime() // get universal time of corresponding time
DateTime l = u.AddHours(7); // plus 7 to hour, get time for Bangkok timezone.

Personally, .NET seems to be easier than PHP. Formatting date and time syntax is much better and more understandable than PHP.

Technorati tags: , , ,

Twitter on PHP!!!

in

Someone said Twitter is built with Ruby on Rails. This picture disproves it.

twitter on php

I took this shot from Twitter’s help page. Neither sling nor stand in were used. Also no stage and Photoshop.

PS. Twitter is the world biggest website that use Ruby on Rails.

Technorati Tags: , , , ,

How to reverse string

in

น่าแปลกใจที่ .NET ไม่มีคำสั่งสำหรับ reverse string แฮะ

C#
public string reverse(string s){
  char[] arrS = s.ToCharArray();
  Array.Reverse( arrS );
  string reversedString = new string( arrS );
  return reversedString;
}

php

$st = 'a string';
$st=strrev($st);

ruby

a = "abcdefg"
a.reverse
=> "gfedcba"

จริงๆของ python ก็ไม่มีคำสั่ง reverse string โดยตรง แต่ว่าใน python มอง string ว่าเป็น sequence type แบบนึง ก็เลยเขียน reverse string แบบนี้ได้

python

a = "abcdefg"
a[::-1]
=>'gfedcba'

รู้สึกว่าของ python จะเท่สุดเนอะ

Technorati tags: , , , , , ,