3 e! }0 S+ m/ G: n% H' H+ \9 v% k# Z+ x! P! E8 h
其實就是ajax檢索: G" B9 \/ Q6 a3 J* ?: P
; z @: h4 ~& B8 o0 Q2 w3 w<?php
0 |2 D& C* w* l+ x% W
" r( n) r7 Q% I& k$word=$_GET['word']; //查詢的關鍵詞5 `2 Y; V7 T5 [$ l$ j# I8 j: H! `
8 b# r8 f" S2 |, e: L! j$ b
if ($word=="")" _; i1 D2 A4 O. A+ A9 z, U
{9 z0 e1 s7 _& H- g1 U. V
echo <<<EOF% q- l, F2 V% @; q' y. M7 s
<form action="" method="get">
! M' o& e, \4 Y0 u3 ^" D% D <p>關鍵詞: <input type="text" name="word" /></p>
$ |. C. F: }& |# | <input type="submit" value="採集" />9 O- _7 B+ \" \$ N6 U$ q
</form>
- S. b. H2 Y5 D" Z# [' fEOF;3 x, Q: {# n0 o% H
}1 g/ ?5 y- D3 o' I8 z! a3 J
else, ?% Z, i4 e1 k5 i8 \0 \8 t
{$ \, o/ a% [' g( [9 e8 t1 E
7 |4 H- l' O+ y& {6 w$data=file_get_contents('http://suggestion.baidu.com/su?wd='.$word);//讀取相關關鍵詞所
: G) C9 }6 v7 }2 J4 k' V6 ?8 u$data=mb_convert_encoding($data, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
, e- o7 [7 f$ D" B$data_temp=strpos($data,"x");
A6 ~4 n% J, l/ d( r& U, P$data=substr_replace($data,"",$data_temp,17);
4 M4 |, G4 n& N8 h( o* A9 N- C+ n$data = trim($data,");");5 z: o* Z1 H+ G) a
$data = trim($data,"{");3 M T: H8 }; g0 ~$ Y7 R
$data=preg_replace("/q:.+?.e,/",'', $data);
' z- u0 b9 x; ?$ h* C; ?. l$data = str_replace("[","",$data);5 N8 k: ?7 J) ]1 T& C
$data = str_replace("]","",$data);
' e0 Y* |0 |. n% z$data = "[".$data."]";) n$ Z9 W: @! z( X( ?
$data = str_replace(",","},s:",$data);
# p2 A' Y5 a/ B$data = str_replace("s:","{\"s\":",$data);//複雜的處理,以符合json格式1 t/ m' F: a% d* K9 ?
$dc=json_decode($data);
$ \3 Y; B7 u( Rfor ($n=0; $n<=9; $n++)
6 d* f* c* [* T. X( [{
5 g; s- j V3 o" A: y; m/ a$wd[$n]=$dc[$n]->s;* }& P, a, n2 v- n( ]
echo "</br>".$wd[$n];' i# l; @, m1 [% X* t% I
}$ T) c% R- b. A8 ]/ \* J
' _/ |9 Q7 a# U* h; _2 S
}( p/ l6 r, Z' W/ ]
?>
6 Z2 ~0 N& C2 J3 S7 h: z$ ?5 c& R& ^# Y2 b7 _
4 ], ^$ W* j. ^' ^% h
% e, X- f% [0 ?% w: k# a4 E
|