Blog Archives

JavaScript: how to load dynamic contents (HTML String, JSON) to iframe

The story Although people are suggesting the replacement of <iframe> by <div> due to the poor usability of <iframe>,  there are still some cases that <iframe> is the only way to go. Consider such case : you want to show a preview screen before the user hit “submit” button on a page with form (the […]

Yet another Javascript Internationalization (i18n) module

i18n? Internationalize (a.k.a. i18n) is a very basic practice when working with multi-lingual websites. A simple i18n mechanism involves only a dictionary containing the pairs of strings, and a dictionary lookup function (e.g. the underscore magic function _() ). Once these two things are ready, the implementation is relatively simple. Major programming frameworks also provide […]

PHP isset() and multi-dimentional array

** The issue discussed in this post has been fixed since PHP5.4.0, so the below discussion and solution are for PHP 5.3.x or lower. Thanks David for clarifying. A few weeks ago I covered how to check the existence of an array element in PHP. In the post I explained why isset() is dangerous to […]

Internet Explorer 8 background disappeared (or becomes white) bug with jQuery 1.6 (or 1.6.1)

Latest Update: This bug has been fixed by jQuery 1.6.2 released on 30/06/2011. If your project has upgraded to jQuery version 1.6 or jQuery 1.6.1, then you should make sure it works fine with Internet Explorer 8 (IE8) before you hit the publish button. This is my two cents. What’s wrong with jQuery 1.6+ and […]

Really simple CSS compression function in PHP

Thanks to the simple syntax of CSS, we can easily compress the CSS code with a PHP function of only 3 lines of codes. Since the compression will remove all the code indention and comments so it should be apply to production codes only. Here is the CSS compression that I used in my projects. […]

Check if an array is associative or sequential(indexed) in PHP

In PHP, depending on the type of the keys in an array, the array can be identified as associative (if the key is a string like $arr[‘mykey’]) or sequential (some may call it indexed, i.e. if the key is an integer like $arr[1], $arr[2], etc.). Although the internal representation of both associative and sequential arrays […]

PHP – isset() vs array_key_exists() : a better way to determine array element’s existence

The story In the CourseYou project, we’re asked to check if an element is set in an array. That is,  we’re asked to determine whether $Arr[‘MyElement’] exists. So we use the following code as a start. <?php if (isset($Arr[‘MyElement’])) { … do my stuff … } ?> This code works fine, but, it works fine […]

Equal (==), identical (===) and array comparison in PHP

Equal (==) If you use equal (==), you are allowing type conversion which means PHP will try to convert the two sides into the same type and then do the comparison. So even if the two sides are NOT the same thing, they MAY still be treat as the SAME. Consider this code: <?php $left […]