네이버의 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를 나타냅니다
게시글 목록
| 번호 | 제목 |
|---|---|
| 978 | |
| 973 |
Flash
wmode
4
|
| 966 |
Flash
플래시 flv(동영상) 사용경험담
4
|
| 960 | |
| 958 |
기타
Top으로 ver2
|
| 956 |
JavaScript
제목에 첫 글자만 스타일적용과 문장의 첫라인 스타일 적용
1
|
| 953 | |
| 941 | |
| 938 | |
| 937 |
Flash
창크기 자동 조절
|
| 936 |
Flash
플래시 메뉴
|
| 929 | |
| 923 |
JavaScript
메모하지 않으면 깜빡깜빡 잊어버리는 것들
3
|
| 922 |
기타
빈 무비클립 만들기
|
| 919 | |
| 918 | |
| 914 |
JavaScript
euc-kr 문서를 utf-8 로 변환
3
|
| 911 | |
| 908 | |
| 907 |
기타
Ajax 흉내 내기
|
| 904 |
JavaScript
포토샵에서 트랜스폼과 카피를 동시에 하는 방법
2
|
| 899 | |
| 896 |
JavaScript
mod_rewrite 설치 법
2
|
| 895 | |
| 892 |
JavaScript
포토샵의 블렌딩 모드
2
|
| 888 |
JavaScript
opacity(투명도) 값 쉽게 먹이기.
3
|
| 882 | |
| 877 |
기타
서버정보검색
1
|
| 873 |
기타
텍스트시계
3
|
| 869 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기