Skip to content

Instantly share code, notes, and snippets.

@kanreisa
Created October 24, 2010 04:37
Show Gist options
  • Save kanreisa/643105 to your computer and use it in GitHub Desktop.
Save kanreisa/643105 to your computer and use it in GitHub Desktop.
XMLデータをJavaScriptで扱うためのJSONP変換APIサンプル
<?php
if( ($_GET['xml'])&&($_GET['callback']) )
{
$url = strip_tags($_GET['xml']);
$callback = strip_tags($_GET['callback']);
header('Content-Type: text/javascript; charset=utf-8');
if( $xml = @simplexml_load_file('http://' . $url) ) {
$json = json_encode($xml);
} else {
$json = 'null';
}
echo $callback . '(' . $json . ');';
}
?>
@kanreisa
Copy link
Author

ライセンスフリー。
実際に利用する場合はキャッシュなどしてやってください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment