Skip to content

Instantly share code, notes, and snippets.

@juwoong
Created October 17, 2014 13:12
Show Gist options
  • Save juwoong/c4d56ffffce38c87e914 to your computer and use it in GitHub Desktop.
Save juwoong/c4d56ffffce38c87e914 to your computer and use it in GitHub Desktop.
searchPlace
<?php
include_once("include.php");
$query = $_POST['query'];
$start = $_POST['start'];
$display = $_POST['display'];
$key = '025346a73ca5b415a722216f8dcef3f5';
$url='http://openapi.naver.com/search?key='.$key.'&query='.$query.'&target=local&start='.$start.'&display='.$display;
$url = parse_url($url);
$fp = fsockopen($url['host'], 80, $errno, $errstr);
fputs($fp,"GET ".$url["path"].($url["query"] ? '?'.$url["query"] : '')." HTTP/1.0\r\n");
fputs($fp,"Host: " . $url["host"] . "\r\n");
fputs($fp,"User-Agent: PHP Script\r\n");
fputs($fp,"Connection: close\r\n\r\n");
$xml_txt = substr(fread($fp,1000000), 151);
$xmlNode = simplexml_load_string($xml_txt);
$arrayData = xmlToArray($xmlNode);
for($i=0; $i<$display; $i++)
{
$data['item'][$i]['title'] = $arrayData['rss']['channel']['item'][$i]['title'];
$data['item'][$i]['mapx'] = $arrayData['rss']['channel']['item'][$i]['mapx'];
$data['item'][$i]['mapy'] = $arrayData['rss']['channel']['item'][$i]['mapy'];
}
ReturnResult($data);
/*preg_match('/<x>.+<\/x>/',$api_txt,$x);
preg_match('/<y>.+<\/y>/',$api_txt,$y);
$x = preg_replace('/[^0-9]/','',$x[0]);
$y = preg_replace('/[^0-9]/','',$y[0]);
$data['status'] = 1;
$data['x'] = $x;
$data['y'] = $y;
ReturnResult($data);
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment