네이버의 openapi에서 키를 받으셔야 사용할수 있습니다.
궁금한 점은 http://openapi.naver.com/15.html 이곳에서 확인하세요.
결과가 간단하므로 복잡하게 처리하지 않고 간단하게 처리햇습니다.
php에서 fopen(), iconv()를 지원하는 환경에서만 가능합니다.
이하 소스
-----------------------------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=euc-kr'>
<title> 인기검색어 </title>
</head>
<body>
<center>
<table width=200 border=1 cellspacing=3>
<?php
$naver_openapi_key = '자신이 네이버에서 발급받은 키를 넣으세요';
$file = 'http://openapi.naver.com/search?key=' . $naver_openapi_key . '&query=nexearch&target=rank';
$fp = fopen($file, 'r') or die($file . ' not found');
$text = '';
while($data = fread($fp, 4096)){
$text .= iconv('UTF-8', 'EUC-KR', $data);
}
fclose($fp);
preg_match_all("'<K>([^<]*)</K>[^<]*<S>([^<]*)</S>[^<]*<V>([^<]*)</V>'s", $text, $matches);
if (is_array($matches[1]) && count($matches[1]) > 0){
foreach($matches[1] as $key => $val){
echo "<tr align='center'><td> " . $val . " </td><td> " . $matches[2][$key] . " </td><td> " . $matches[3][$key] . " </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 환경에서 사용할려면
<meta http-equiv='Content-Type' content='text/html; charset=euc-kr'> 을
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'> 로 바꾸고
$text .= iconv('UTF-8', 'EUC-KR', $data); 을
$text .= $data; 로 바꾸시면 됩니다.
데모로 걸은 링크 사이트는 며칠후에는 안보일수 있습니다
http://search.dyd.cc/favorites_word.php<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
궁금한 점은 http://openapi.naver.com/15.html 이곳에서 확인하세요.
결과가 간단하므로 복잡하게 처리하지 않고 간단하게 처리햇습니다.
php에서 fopen(), iconv()를 지원하는 환경에서만 가능합니다.
이하 소스
-----------------------------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=euc-kr'>
<title> 인기검색어 </title>
</head>
<body>
<center>
<table width=200 border=1 cellspacing=3>
<?php
$naver_openapi_key = '자신이 네이버에서 발급받은 키를 넣으세요';
$file = 'http://openapi.naver.com/search?key=' . $naver_openapi_key . '&query=nexearch&target=rank';
$fp = fopen($file, 'r') or die($file . ' not found');
$text = '';
while($data = fread($fp, 4096)){
$text .= iconv('UTF-8', 'EUC-KR', $data);
}
fclose($fp);
preg_match_all("'<K>([^<]*)</K>[^<]*<S>([^<]*)</S>[^<]*<V>([^<]*)</V>'s", $text, $matches);
if (is_array($matches[1]) && count($matches[1]) > 0){
foreach($matches[1] as $key => $val){
echo "<tr align='center'><td> " . $val . " </td><td> " . $matches[2][$key] . " </td><td> " . $matches[3][$key] . " </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 환경에서 사용할려면
<meta http-equiv='Content-Type' content='text/html; charset=euc-kr'> 을
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'> 로 바꾸고
$text .= iconv('UTF-8', 'EUC-KR', $data); 을
$text .= $data; 로 바꾸시면 됩니다.
데모로 걸은 링크 사이트는 며칠후에는 안보일수 있습니다
http://search.dyd.cc/favorites_word.php<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
댓글 4개
19년 전
좋은 팁들 감사드립니다.
혹시 검색어에 링크가 되게할 수는 없는지요.
혹시 검색어에 링크가 되게할 수는 없는지요.
19년 전
네 물론 가능하지요
foreach 부분을 다음과 같이 고쳐 주시면 됩니다.
----------------------------------------------------------------------------------------------------------------------------------------------------
foreach($matches[1] as $key => $val){
$link = 'http://search.naver.com/search.naver?where=nexearch&query=' . urlencode($val);
echo "<tr align='center'><td> <a href='" . $link . "' target='_blank'>" . $val . "</a> </td><td> " . $matches[2][$key] . " </td><td> " . $matches[3][$key] . " </td></tr>";
}
-------------------------------------------------------------------------------------------------------------------------------------------------------
foreach 부분을 다음과 같이 고쳐 주시면 됩니다.
----------------------------------------------------------------------------------------------------------------------------------------------------
foreach($matches[1] as $key => $val){
$link = 'http://search.naver.com/search.naver?where=nexearch&query=' . urlencode($val);
echo "<tr align='center'><td> <a href='" . $link . "' target='_blank'>" . $val . "</a> </td><td> " . $matches[2][$key] . " </td><td> " . $matches[3][$key] . " </td></tr>";
}
-------------------------------------------------------------------------------------------------------------------------------------------------------
19년 전
감사합니다. 바로 적용해주셨네요. 좋은 공부가 될 것 같습니다.
19년 전
웹검색으로 바로가게 할려면요
위의
$link = 'http://search.naver.com/search.naver?where=nexearch&query=' . urlencode($val);
부분을
$link = 'http://web.search.naver.com/search.naver?where=web&query=' . urlencode($val);
이렇게 바꿔주기만 하면 됩니다.
위의
$link = 'http://search.naver.com/search.naver?where=nexearch&query=' . urlencode($val);
부분을
$link = 'http://web.search.naver.com/search.naver?where=web&query=' . urlencode($val);
이렇게 바꿔주기만 하면 됩니다.
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 230 | 20년 전 | 2079 | ||
| 229 | 20년 전 | 3146 | ||
| 228 | 20년 전 | 3337 | ||
| 227 | 20년 전 | 2414 | ||
| 226 | 20년 전 | 5493 | ||
| 225 | 20년 전 | 2531 | ||
| 224 | 20년 전 | 2973 | ||
| 223 | 20년 전 | 4211 | ||
| 222 | 20년 전 | 2612 | ||
| 221 | 20년 전 | 2298 | ||
| 220 | 20년 전 | 3685 | ||
| 219 | 20년 전 | 2083 | ||
| 218 | 20년 전 | 3575 | ||
| 217 | 20년 전 | 2489 | ||
| 216 | 20년 전 | 2926 | ||
| 215 | 20년 전 | 2234 | ||
| 214 | 20년 전 | 3347 | ||
| 213 | 20년 전 | 2925 | ||
| 212 | 20년 전 | 3063 | ||
| 211 | 20년 전 | 2153 | ||
| 210 | 20년 전 | 1910 | ||
| 209 | 20년 전 | 2366 | ||
| 208 | 20년 전 | 1993 | ||
| 207 | 20년 전 | 1685 | ||
| 206 | 20년 전 | 1861 | ||
| 205 | 20년 전 | 3956 | ||
| 204 | 20년 전 | 1683 | ||
| 203 | 20년 전 | 2020 | ||
| 202 | 20년 전 | 2361 | ||
| 201 | 20년 전 | 1836 | ||
| 200 | 20년 전 | 2965 | ||
| 199 | 20년 전 | 2011 | ||
| 198 | 20년 전 | 2093 | ||
| 197 | 20년 전 | 3665 | ||
| 196 | 20년 전 | 2999 | ||
| 195 | 20년 전 | 2106 | ||
| 194 | 20년 전 | 10259 | ||
| 193 | 20년 전 | 2256 | ||
| 192 | 20년 전 | 1613 | ||
| 191 | 20년 전 | 2678 | ||
| 190 | 20년 전 | 2299 | ||
| 189 | 20년 전 | 1697 | ||
| 188 | 20년 전 | 1495 | ||
| 187 | 20년 전 | 1919 | ||
| 186 | 20년 전 | 1743 | ||
| 185 | 20년 전 | 1788 | ||
| 184 | 20년 전 | 2373 | ||
| 183 | 20년 전 | 1578 | ||
| 182 | 20년 전 | 1491 | ||
| 181 | 20년 전 | 1634 | ||
| 180 | 20년 전 | 2732 | ||
| 179 | 20년 전 | 1816 | ||
| 178 | 20년 전 | 1865 | ||
| 177 | 20년 전 | 1991 | ||
| 176 | 20년 전 | 1809 | ||
| 175 | 20년 전 | 1878 | ||
| 174 | 20년 전 | 1703 | ||
| 173 | 20년 전 | 2067 | ||
| 172 | 20년 전 | 1791 | ||
| 171 | 20년 전 | 2572 | ||
| 170 | 20년 전 | 2284 | ||
| 169 | 20년 전 | 2564 | ||
| 168 | 20년 전 | 1497 | ||
| 167 | 20년 전 | 1587 | ||
| 166 | 20년 전 | 2168 | ||
| 165 | 20년 전 | 1645 | ||
| 164 | 20년 전 | 3782 | ||
| 163 | 20년 전 | 2682 | ||
| 162 | 20년 전 | 2099 | ||
| 161 | 20년 전 | 2813 | ||
| 160 | 20년 전 | 1742 | ||
| 159 | 20년 전 | 1623 | ||
| 158 | 20년 전 | 2573 | ||
| 157 | 20년 전 | 1502 | ||
| 156 | 20년 전 | 1752 | ||
| 155 | 20년 전 | 3238 | ||
| 154 | 20년 전 | 1913 | ||
| 153 | 20년 전 | 1634 | ||
| 152 | 20년 전 | 4969 | ||
| 151 | 20년 전 | 4589 | ||
| 150 | 20년 전 | 3524 | ||
| 149 | 20년 전 | 3811 | ||
| 148 | 20년 전 | 7094 | ||
| 147 | 20년 전 | 3563 | ||
| 146 | 20년 전 | 2640 | ||
| 145 | 20년 전 | 2630 | ||
| 144 | 20년 전 | 7174 | ||
| 143 | 20년 전 | 4615 | ||
| 142 | 20년 전 | 1908 | ||
| 141 | 20년 전 | 3255 | ||
| 140 | 20년 전 | 1970 | ||
| 139 | 20년 전 | 1592 | ||
| 138 | 20년 전 | 2316 | ||
| 137 | 20년 전 | 1792 | ||
| 136 | 20년 전 | 1463 | ||
| 135 | 20년 전 | 1802 | ||
| 134 | 20년 전 | 2973 | ||
| 133 | 20년 전 | 2457 | ||
| 132 | 20년 전 | 1713 | ||
| 131 | 20년 전 | 1660 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기