Googleããçºæ¿ã¬ã¼ããJSONã§åå¾ããæ¹æ³
ä»äºã§çºæ¿ã¬ã¼ããæ±ãå¿
è¦ããã£ãã®ã§ã¡ãã£ã¨èª¿ã¹ã¦ã¿ã¾ããã
æµ·å¤ã«ããAPIã¯ææã ã£ãããYahooãã¡ã¤ãã³ã¹ããã´ãã§ã´ãã§ããã®ãã³ã¼ãè¦ããããã©ããããã ã»ã»ã»ã¨ãæã£ã¦ããGoogleå
çã«ã¹ãããªAPIãè¦ã¤ãã¾ããã
http://www.google.com/ig/calculator?hl=ja&q=å¤æåã®é貨=?å¤æå¾ã®é貨 // 1ã¢ã¡ãªã«ãã« ãæ¥æ¬åã« http://www.google.com/ig/calculator?hl=ja&q=1USD=?JPY
PHPã§æ¸ãã¨ãããªæãã§ä½¿ãã¾ããAPIã¬ã¹ãã³ã¹ã®ã¾ã¾ã ã¨json_decode()ãæååã®ãã¼ã¹ã«å¤±æãã¦ãã®ã§keyå¤ãã"ãã§å²ã£ã¦ã¾ãï¼ããµã¤ã»ã»ï¼ã
<?php $data = file_get_contents('http://www.google.com/ig/calculator?hl=en&q=1USD=?JPY'); $data = str_replace(array('lhs', 'rhs', 'error', 'icc'), array('"lhs"', '"rhs"', '"error"', '"icc"'), $data); $json = json_decode($data, true); $yen = preg_replace("/[^0-9.]+/", '', $json['rhs']); var_dump($yen);
ãã¡ã¤ãã³ã¹ãµã¤ãããé å¼µã£ã¦ã´ãã§ã´ãã§ããããã楽ãªã®ã§ãªã¹ã¹ã¡ã§ãã
追è¨
ãã³ã¡ã§id:reasonofreasonãããããã«ã¯ãªã¼ãã¼ã·ã§ã³ã§å²ã¾ãã¦ãªãããå²ãå¿ è¦ãããã¨ãããã¨ãªã®ã ãããããã¨ããã³ã¡ã³ããããã£ãã®ã§è£è¶³ãã¦ããã¾ããjson_decodeã¯JSONè¨æ³ãå³å¯ã«ãã§ãã¯ããã®ã§keyå¤ãã¯ã©ã¼ãã¼ã·ã§ã³ã§å²ãã§ãªãã¨ãã¼ã¹ãã¦ãããªãã®ã§ããåãã§ãã¯ã¯çãããã«ããããæã¯å³å¯ã ã£ããããPHPãªã®ã§ããã
åèãªã³ã¯