네이버의 openapi에서 키를 받으셔야 사용할수 있습니다.
궁금한 점은 http://openapi.naver.com/15.html 이곳에서 확인하세요.
결과가 간단하므로 복잡하게 처리하지 않고 간단하게 처리햇습니다.
php에서 fopen()을 지원하는 환경에서만 가능합니다.
파일저장을 UTF-8 로 하여야만 에러가 나지 않습니다.
이하 소스
-----------------------------------------------------------------------------------------------------------
<?php
$q = (!empty($_GET['q'])) ? $_GET['q'] : '';
$q_decode = (!empty($q)) ? stripslashes(urldecode($q)) : '';
$q_enocde = urlencode($q);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<title> 한국어 사전 </title>
</head>
<body>
<center>
<form method='GET'>
<input type=text name='q' value='<?=$q_decode?>'> <input type='submit' value='search'>
</form>
<table width=600 border=1 cellspacing=3>
<?php
if (!empty($q_decode)) {
$naver_openapi_key = '자신이 네이버에서 발급받은 키를 넣으세요';
$file = 'http://openapi.naver.com/search?key=' . $naver_openapi_key . '&query=' . $q_enocde . '&display=100&start=1&target=krdic';
$fp = fopen($file, 'r') or die($file . ' not found');
$text = '';
while($data = fread($fp, 4096)){
$text .= $data;
}
fclose($fp);
preg_match_all("'<item>[^<]*<title>([^<]*)</title>[^<]*<link>([^<]*)</link>'s", $text, $matches);
if (is_array($matches[1]) && count($matches[1]) > 0){
foreach($matches[1] as $key => $val){
echo "<tr align='center'><td> <a href='" . $matches[2][$key] . "' target='_blank'>" . str_replace(array("<", ">"), array("<", ">"), $val) . "</a> </td><td> <a href='" . $matches[2][$key] . "' target='_blank'>" . $matches[2][$key] . "</a> </td></tr>";
}
}
else echo "<tr><td>검색결과 없음</td></tr>";
}
else echo "<tr><td>검색어를 입력하세요</td></tr>";
?>
</table>
<br><a href='http://openapi.naver.com/' target='_blank'>네이버 OPENAPI 사용</a>
</center>
</body>
</html>
-----------------------------------------------------------------------------------------------------------
utf-8 환경에서만 사용가능합니다.
데모로 걸은 링크 사이트는 며칠후에는 안보일수 있습니다
http://search.dyd.cc/krdic.php?q=%ED%95%9C%EA%B5%AD<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
궁금한 점은 http://openapi.naver.com/15.html 이곳에서 확인하세요.
결과가 간단하므로 복잡하게 처리하지 않고 간단하게 처리햇습니다.
php에서 fopen()을 지원하는 환경에서만 가능합니다.
파일저장을 UTF-8 로 하여야만 에러가 나지 않습니다.
이하 소스
-----------------------------------------------------------------------------------------------------------
<?php
$q = (!empty($_GET['q'])) ? $_GET['q'] : '';
$q_decode = (!empty($q)) ? stripslashes(urldecode($q)) : '';
$q_enocde = urlencode($q);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<title> 한국어 사전 </title>
</head>
<body>
<center>
<form method='GET'>
<input type=text name='q' value='<?=$q_decode?>'> <input type='submit' value='search'>
</form>
<table width=600 border=1 cellspacing=3>
<?php
if (!empty($q_decode)) {
$naver_openapi_key = '자신이 네이버에서 발급받은 키를 넣으세요';
$file = 'http://openapi.naver.com/search?key=' . $naver_openapi_key . '&query=' . $q_enocde . '&display=100&start=1&target=krdic';
$fp = fopen($file, 'r') or die($file . ' not found');
$text = '';
while($data = fread($fp, 4096)){
$text .= $data;
}
fclose($fp);
preg_match_all("'<item>[^<]*<title>([^<]*)</title>[^<]*<link>([^<]*)</link>'s", $text, $matches);
if (is_array($matches[1]) && count($matches[1]) > 0){
foreach($matches[1] as $key => $val){
echo "<tr align='center'><td> <a href='" . $matches[2][$key] . "' target='_blank'>" . str_replace(array("<", ">"), array("<", ">"), $val) . "</a> </td><td> <a href='" . $matches[2][$key] . "' target='_blank'>" . $matches[2][$key] . "</a> </td></tr>";
}
}
else echo "<tr><td>검색결과 없음</td></tr>";
}
else echo "<tr><td>검색어를 입력하세요</td></tr>";
?>
</table>
<br><a href='http://openapi.naver.com/' target='_blank'>네이버 OPENAPI 사용</a>
</center>
</body>
</html>
-----------------------------------------------------------------------------------------------------------
utf-8 환경에서만 사용가능합니다.
데모로 걸은 링크 사이트는 며칠후에는 안보일수 있습니다
http://search.dyd.cc/krdic.php?q=%ED%95%9C%EA%B5%AD<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
댓글 3개
네이버에서 그이상은 제공해 주지 않고 있습니다 ㅎㅎ
참고부분입니다
http://openapi.naver.com/07.html
rss - 디버그를 쉽게 하고 RSS 리더기만으로 이용할 수 있게 하기 위해 만든 RSS 포맷의 컨테이너이며 그 외의 특별한 의미는 없습니다.
channel - 검색 결과를 포함하는 컨테이너입니다. 이 안에 있는 title, link, description 등의 항목은 참고용으로 무시해도 무방합니다.
lastBuildDate datetime 검색 결과를 생성한 시간입니다.
total integer 검색 결과 문서의 총 개수를 의미합니다.
start integer 검색 결과 문서 중, 문서의 시작점을 의미합니다.
display integer 검색된 검색 결과의 개수입니다.
item - 개별 검색 결과이며, title, link, description을 포함합니다.
title string 검색 결과 문서의 제목을 나타냅니다. 제목에서 검색어와 일치하는 부분은 <b> 태그로 감싸져 있습니다.
link string 검색 결과 문서의 하이퍼텍스트 link를 나타냅니다
참고부분입니다
http://openapi.naver.com/07.html
rss - 디버그를 쉽게 하고 RSS 리더기만으로 이용할 수 있게 하기 위해 만든 RSS 포맷의 컨테이너이며 그 외의 특별한 의미는 없습니다.
channel - 검색 결과를 포함하는 컨테이너입니다. 이 안에 있는 title, link, description 등의 항목은 참고용으로 무시해도 무방합니다.
lastBuildDate datetime 검색 결과를 생성한 시간입니다.
total integer 검색 결과 문서의 총 개수를 의미합니다.
start integer 검색 결과 문서 중, 문서의 시작점을 의미합니다.
display integer 검색된 검색 결과의 개수입니다.
item - 개별 검색 결과이며, title, link, description을 포함합니다.
title string 검색 결과 문서의 제목을 나타냅니다. 제목에서 검색어와 일치하는 부분은 <b> 태그로 감싸져 있습니다.
link string 검색 결과 문서의 하이퍼텍스트 link를 나타냅니다
게시글 목록
| 번호 | 제목 |
|---|---|
| 11690 |
PHP
한국 IP대역 체크
|
| 11689 | |
| 11688 | |
| 11687 |
JavaScript
중첩없이 랜덤수 뽑아내기
|
| 11686 | |
| 11685 | |
| 11684 | |
| 11682 |
JavaScript
자바스크립트에서 for문 사용시 속도차이
1
|
| 11679 | |
| 11675 |
Mobile
html5 지원되는 os별 버전보기
3
|
| 11674 | |
| 11673 | |
| 11669 | |
| 11668 | |
| 11667 | |
| 11658 | |
| 11657 | |
| 11635 | |
| 11633 |
JavaScript
그누보드5 에 Daum 우편번호 찾기 API 연동 하기
1
|
| 11632 |
JavaScript
그누보드4 에 Daum 우편번호 찾기 API 연동 하기.
|
| 20292 | |
| 11631 | |
| 11630 | |
| 11628 |
MySQL
MYSQL 기본 명령어들 모음
1
|
| 11625 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기