네이버의 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를 나타냅니다
게시글 목록
| 번호 | 제목 |
|---|---|
| 11764 |
PHP
파일 처리 함수(3)
|
| 11763 |
PHP
파일 처리 함수(2)
|
| 11762 |
PHP
날짜 및 시간 함수
|
| 11761 |
PHP
파일 처리 함수(1)
|
| 11760 |
PHP
문자열 함수(5)
|
| 11759 |
PHP
문자열 함수(4)
|
| 11758 |
PHP
문자열 함수(3)
|
| 11757 |
PHP
문자열 함수(2)
|
| 11756 |
PHP
문자열 함수(1)
|
| 11755 |
PHP
사용자 정의 함수(3)
|
| 11754 |
PHP
사용자 정의 함수(2)
|
| 11753 |
PHP
사용자 정의 함수(1)
|
| 11752 |
PHP
그 밖의 제어문
|
| 11751 |
PHP
반복 제어문(2)
|
| 11750 |
PHP
반복 제어문(1)
|
| 11749 |
PHP
조건 제어문(2)
|
| 11748 |
PHP
조건 제어문(1)
|
| 11747 |
PHP
비교 연산자, 논리 연산자
|
| 11746 |
PHP
산술 연산자, 대입 연산자
|
| 11745 | |
| 11744 |
PHP
가변 변수
|
| 11743 |
PHP
정적 변수
|
| 11742 |
PHP
전역 변수
|
| 11741 |
PHP
배열 변수
|
| 11740 |
PHP
변수 사용법
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기