에러 관련 질문
본문
네이버 검색 api로 들고오는데요.
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in 어디어디 on line 3
이런 에러가 뜨는데 왜그런건가요?
다른 홈페이지에서는 잘되던데
혹시 php 버전이 낮아서 그런가요???
(PHP4, Mysql 4.x) 이네요....
요즘 7 쓰는데 4면.... ㅠ
<?php
class NaverProxy {
public function queryNaver($query, $target) {
$client_id = "ㅁㅁㅁ";
$client_secret = "ㅂㅂㅂ";
$query=urlencode("얍얍");
$target="blog";
$url = "https://openapi.naver.com/v1/search/blog.xml";
$url = sprintf("%s?query=%s&display=100&start=1&sort=sim&target=blog", $url, $query);
$is_post = true;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_GET, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "X-Naver-Client-Id: ".$client_id;
$headers[] = "X-Naver-Client-Secret: ".$client_secret;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec ($ch);
curl_close ($ch);
return $data;
}
}
$naverproxy = new NaverProxy();
// XML파일에서 원하는 항목만 추출하기
//echo $naverproxy -> queryNaver($_POST['query'], $_POST['target']);
$xmlstring = $naverproxy -> queryNaver($_POST['query'], $_POST['target']);
$xml = simplexml_load_string($xmlstring) or die("에러: 객체를 생성할 수 없습니다");
$items = $xml->channel->item;
if(!empty($items)){
foreach($items as $item){
echo '<a href="' . $item->link . '">' . $item->title . '</a><br>';
}
}
?>
!-->
답변을 작성하시기 전에 로그인 해주세요.