戻る

XML、JSONをJSONPに変換する

XMLをJSONPに変換する

xml2jsonp.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.');';
}
?>

JSONをJSONPに変換する

json2jsonp.php

<?
if(($_GET['json'])&&($_GET['callback'])){
	$url		= strip_tags($_GET['json']);
	$callback	= strip_tags($_GET['callback']);
	
	header('Content-Type: text/javascript; charset=utf-8');
	
	if($json = @file_get_contents('http://'.$url)){
		//
	}else{
		$json	= 'null';
	}
	
	echo $callback.'('.$json.');';
}
?>

inserted by FC2 system