Tuesday, August 28, 2012

PHP : Convert Array To String(การแปลงจากตัวแปรชุดเป็นข้อความ)

PHP : Convert Array To String(การแปลงจากตัวแปรชุดเป็นข้อความ)


<?
   $arr=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
   $str=implode(',',$arr);
   print $str;

?>

Result (ผลลัพธ์)
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z




BY N1B

Monday, August 27, 2012

JQuery : Multiple jQuery Get Scripts


/* enhance $.getSctipt to handle mutiple scripts */
var getScript = jQuery.getScript;
jQuery.getScript = function( resources, callback ) {

    var // reference declaration & localization
    length = resources.length,
    handler = function() { counter++; },
    deferreds = [],
    counter = 0,
    idx = 0;

    for ( ; idx < length; idx++ ) {
        deferreds.push(
            getScript( resources[ idx ], handler )
        );
    }

    jQuery.when.apply( null, deferreds ).then(function() {
        callback && callback();
    });
};

$.getScript(['script1.js','script2.js','script3.js'], function() {
    //do something after all scripts have loaded
});

//or seperate into an array to include

var scripts = ['script1.js','script2.js','script3.js'];
$.getScript(scripts, function(data, textStatus) {
    //do something after all scripts have loaded
});

Tuesday, August 21, 2012

PHP : Get Client IP


ฟังชั่นนี้เป็นการแสดงค่า IP ของเครื่องคอมพิวเตอร์ที่ เข้ามาดูเว็บเรานะครับ

function getClientIP(){
   if(!empty($_SERVER['HTTP_CLIENT_IP'])){
     $ip=$_SERVER['HTTP_CLIENT_IP'];
   }
   else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
     $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
   }
   else {
     $ip=$_SERVER['REMOTE_ADDR'];
   }
   return $ip;
}

print getClientIP();


BY N1B