ܻؤ1顪30奵꡼ޥܥ

ITȤƯ30奵꡼ޥΥ饤ߥ󥰵Ͽ

2009ǯ08

βҤƱη뺧2˻á
ʤĤƱäƤɡճȤߤʷ뺧Ƥ
졦ޤ28ФʤΤˡ

֡ȥ


2ܡ3ܤ³Ƶסˤäߤޤ
ߤʤƱФʤɡ㤤ʡäƻפäƤޤä

ҼƤ礤ƱȤǯǾιŪʤΤ򤷤ƤΤǡ
ߤʷ뺧Ƥ³ƤȤʡ

뺧2ν

μ̿ΤˤϿϺΥä
ޤ(o)
    Υȥ꡼ϤƤʥ֥åޡɲ

ɽȤˤդȻפäΤǥ⡣

ȤȤϤʴǻȤ
function number_format(num) {
  return num.toString().replace(/([0-9]+?)(?=(?:[0-9]{3})+$)/g , '$1,')
}

    Υȥ꡼ϤƤʥ֥åޡɲ

ǯԤäƤޤ
Ѥ餺κ֤ꡣ

ޤϳƹβ椫鸫Ʋޤ
ʤǯͤʤ
㺮ǤΤϤʤǤɡ

Х֤ȤȤɥĤΥȤ٤Ǥ
äѤ결ܤ̣֤ʤäƻפޤ

̿硼ܤƤ롼ʡϡ
۽ǼäޤĤ
    Υȥ꡼ϤƤʥ֥åޡɲ

ȸ 21 Really Useful & Handy PHP Code Snippets
if(!emptyempty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){  
 //If AJAX Request Then  
}else{  
 //something else  
} 
    Υȥ꡼ϤƤʥ֥åޡɲ

Ƶ٤ߤäΤǼ²Ȥ˵äƤޤ

ϲʤΤǡ֤鲹äƥä
μ̿εƻ֤֤黶⤷Ƥޤ




轵Ż
    Υȥ꡼ϤƤʥ֥åޡɲ

դjsonpȤȻפä ֤ܤΥɥɲϤ­ʤ̵̤˻֤ä
˺ʤ褦˥⡣

$.ajax({
    type: "GET",
    url: "http://sample.com/",
    data: {
      "param": "hogehoge",
    },
    dataType: "jsonp",
    jsonp: "callBack",
    success: function(data) {
      /* success */
    },
    complete: function(data) {
      /* complete */
    }
});

dataTypejsonpˤjQuerycallbackѥ᡼ưƤ롣

callback=jsonp1234391216435ߤʡ

jsonpץդȢcallbackʬꤷ̾ˤǤ롣
¦APIˤäcallbackΥѥ᡼̾Ƥ礬ΤǤȤ˻Ȥ


callbackؿꤷdataץ˽񤯡

data: { "callback" : "hoge" }

callbackؿꤷʤjQueryǰʲΥɤ¹Ԥ롣
window[ 'jsonp1242391216435' ] = function(tmp){
  data = tmp;
  success();
  complete();
  // ١쥯Ƚ
  window[ jsonp ] = undefined;
  try{ delete window[ jsonp ]; } catch(e){}
  if ( head )
  head.removeChild( script );
}


¦ϤʤΤǤȤꤢǡ֤Ƥߤ
֤ǡϤˡ
<?php
$data = array("a" => "hoge", "b" => "foo", "c" => "bar");
$json = json_encode($data);
$callback = htmlspecialchars(strip_tags($_GET["callback"]));
echo $callback . "(" . $json . ")";
?>
    Υȥ꡼ϤƤʥ֥åޡɲ

5ގَ
äAmazon᡼ƤΤбƤߤޤ
꤮ˤʤʤȤʤ
Ƶ٤ߤνȤäǤ

Ȥ櫓ǺޤϤƤparamȥåȥϤ
URL֤Ƥؿ

˼ʬѡ
֤ͤϤѤȤ͡

function amazonSignature ($param=array(), $secretKey="") {
  $aws = array("host" => "webservices.amazon.co.jp", "path" => "/onca/xml");
  ksort($param);

  $reqParam = array();
  foreach ($param as $key => $val) {
    $reqParam[] = $key . "=" . rawurlencode($val);
  }

  $paramStr = implode("&", $reqParam);
  $str = implode("\n", array('GET', $aws["host"], $aws["path"], $paramStr));
  $sig = rawurlencode( base64_encode( hash_hmac("sha256", $str, $secretKey, true)));
  $reqParam[] = "Signature=" . $sig;
  $url = "http://" . $aws["host"]. $aws["path"] . "?" . implode("&", $reqParam);

  return $url;
}

ʤߤparamˤϤʴΥǡ
ˤ碌ѹ
$param = array(
               "Service" => "AWSECommerceService",
               "AWSAccessKeyId" => "YOUR ACCESS KEY",
               "Operation" => "ItemSearch",
               "SearchIndex" => "Books",
               "ResponseGroup" => "Medium,Tracks",
               "BrowseNode" => "465610",
               "Timestamp" => gmdate("Y-m-d\TH:i:s\Z"),
               );
    Υȥ꡼ϤƤʥ֥åޡɲ

ȤȤǿҳߤäƤޤ
ŷۤǤŷˤʤޤ

֤äƼǤ硼ڤä
ƤФäǤʡ

٤äɡǯ֤
뤫ä餹

ʤʢˤʤäƤƥåΤܤǤ
ζǤʤ󤫤ΤˤʤäƤޤʼ̿
ҳ
    Υȥ꡼ϤƤʥ֥åޡɲ

ȤǥԥڤǻȤ褦˥⡣

ܸʸϤȥե졼ФƤ롣
ʡοǿ礭ۤɽ٤⤤
appid
쥹ݥ󥹷jsonxmlphp serializeǽ
*)jQueryѡ


ɤϰʲ
$(function(){
  $("#postSentence").submit(function() {
    $("#postResult").empty();
    search($("#sentence").val());
    return false;
  });
  function search(text) {
    $("#postResult").text("Now Loading....");
    $.ajax({
      dataType: "jsonp",
      data: {
        "appid":"your appid",
        "sentence":text,
        "output":"json",
        "max-result":10,
      },
      cache: true,
      url: "http://jlp.yahooapis.jp/KeyphraseService/V1/extract",
      success: function(data) {
        var ul = $(document.createElement("ul"));
        ul.addClass("class20090807");
        $.each(data, function(word, score) {
          ul.append($(document.createElement("li"))
          .append(word)
          .append(' ('+score+')'));
        });
        $("#postResult").html(ul);
      }
    });
  }
});
    Υȥ꡼ϤƤʥ֥åޡɲ

ΥڡΥȥåץ