: M2 i7 n- Q4 F& n) ]# I1 t# w: L% p5 t1 G8 \
其實就是ajax檢索' D# s( N, l/ h
J0 G- p+ p4 T; n<?php# g1 G4 [; c, f/ g2 z5 r; y. N
8 S$ k5 R a% z- J7 H5 |
$word=$_GET['word']; //查詢的關鍵詞
( F' a/ C. X/ N+ {4 ]( m A s
& q0 Y# A" @" Y) Yif ($word=="")( j6 ]% ]$ d4 L2 e7 g
{
" N1 _+ {4 [; H% C# Mecho <<<EOF( e- G5 e! |) m+ n" U( P2 F
<form action="" method="get">
" q: C) q" E/ A8 a <p>關鍵詞: <input type="text" name="word" /></p>/ ^8 o, F: }' Z% _' }
<input type="submit" value="採集" />4 k( {/ T! Y8 {9 V# Y5 u
</form>- B, a% A1 n% t
EOF;
, q' `) r) H/ A# z9 w}3 Z& t1 _& S3 d
else1 [4 z' f6 B0 ]$ \9 P6 L! N5 [! h
{* C1 N b5 h/ [ c6 T6 L: B3 I6 h. m& v; E
0 ^* l8 j6 [, e; M8 F& i$data=file_get_contents('http://suggestion.baidu.com/su?wd='.$word);//讀取相關關鍵詞所: T: X/ b7 B0 K9 {5 ]* H+ G z) F
$data=mb_convert_encoding($data, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );) T: L& ?( m% Y6 A0 W6 ?
$data_temp=strpos($data,"x"); . W+ Y& t z0 }% p e+ \' l
$data=substr_replace($data,"",$data_temp,17);
1 ?. ~5 d( ~0 y1 L" B8 m$data = trim($data,");");& Y5 A5 u N- k+ I1 W
$data = trim($data,"{");
' Q. Z+ W8 ~8 W6 `$data=preg_replace("/q:.+?.e,/",'', $data); 5 C7 e# \7 c* z/ K
$data = str_replace("[","",$data);% Y/ h) p' y. v. Y- h
$data = str_replace("]","",$data);
" d( j2 A& k+ | q- A/ z4 g* }, _8 y* |, [$data = "[".$data."]";) R; S1 A; |" I7 D0 g
$data = str_replace(",","},s:",$data);
9 x9 m! @) j9 }; c7 O3 S# v$data = str_replace("s:","{\"s\":",$data);//複雜的處理,以符合json格式% A7 H( \0 Z' d) m7 l
$dc=json_decode($data);
% W0 r; v# R. n. e4 Z7 d# zfor ($n=0; $n<=9; $n++)7 g; r4 C( f1 s% R* O2 [- w1 p0 Q8 z( [
{% T8 y( i% }3 C* ?- E. m
$wd[$n]=$dc[$n]->s;
3 x3 f9 \9 O" w+ z& s. C! mecho "</br>".$wd[$n];
; C9 A5 P) |3 A4 @* }6 |} t( a; }/ t( W! a/ U0 A
~+ ], o* U1 K# \" j
}
n5 k" a9 C) ^/ \?>$ i6 K. H8 i: O1 p( r) u- V" t
% M8 P; a, A I; O7 b7 O1 ?
. |! k& b4 X+ V1 d4 ~2 w( R, O
: d7 U% A+ T, h- \+ O# [3 i0 X; y |