네이버의 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를 나타냅니다
게시글 목록
| 번호 | 제목 |
|---|---|
| 11424 | |
| 20668 | |
| 11420 | |
| 20222 | |
| 11418 | |
| 11416 |
PHP
우분투 서버 셋팅하는 방법
1
|
| 11413 | |
| 11410 | |
| 11408 |
MySQL
트리거를 이용하여 날짜 자동 업데이트법
1
|
| 11407 | |
| 11402 |
MySQL
mysql 환경 설정
4
|
| 11397 |
JavaScript
달력소스입니다.
4
|
| 11385 |
PHP
웹사이트 주소 알아내기
11
|
| 11382 |
기타
오라클바인딩기술
2
|
| 11379 | |
| 20665 | |
| 11375 | |
| 11373 | |
| 11369 |
정규표현식
IE11에서 사라지는것들이랍니다~
3
|
| 11368 | |
| 20205 | |
| 11360 |
기타
웹접근성 인증 방법
7
|
| 11354 |
MySQL
my-sql 서브쿼리^^
5
|
| 11352 |
MySQL
기초적인 my sql 쿼리문~
1
|
| 11349 |
jQuery
xhtml vs json
2
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기