How to take out Baidu a ranking of 50 and in each add prefix?

Source: Internet
Author: User
such as Http://top.baidu.com/buzz?b=26&c=1&fr=topcategory_c1


Reply to discussion (solution)

The main??? has been Integration??, plus, what do you want to do?

 (.*?) <\/td>/is ', $content, $keywords); $data = $keywords [1]; $result = Array (); foreach ($data as $val) {Preg_match_all ('/ (.*?) <\/a>/is ', $val, $tmp); Array_push ($result, Array (' name ' = = $tmp [2][0], ' url ' = ' http://top.baidu.com '. substr ($tmp [1][0],1));} return $result;} function GETTC ($content) {//Tcpreg_match_all ('/(.*?) <\/td>/is ', $content, $TC); $data = $TC [1]; $result = Array (); foreach ($data as $val) {Preg_match_all ('/(. *?) <\/a>/is ', $val, $tmp); Array_push ($result, Array (' brief ' = $tmp [1][0], ' news ' + $tmp [1][1], ' Tieba ' =>$ TMP[1][2]));} return $result;} function Getnum ($content) {//Lastpreg_match_all ('/(.*?) <\/td>/is ', $content, $last); Icon-rise up Icon-fall down$data = $last [1]; $result = Array (); foreach ($data as $val) {Preg_match_all ('/
 
  
   (.*?) <\/span>/is ', $val, $tmp); Array_push ($result, Array (' Flag ' =>str_replace (' icon-', ' ", $tmp [1][0]), ' num ' = > $tmp [2][0]);} return $result;} $url = ' http://top.baidu.com/buzz?b=26&c=1&fr=topcategory_c1 '; $content = GetContent ($url); $result = Array (); $keywords = GetKeywords ($content), $TC = GETTC ($content), $num = Getnum ($content), for ($i =0, $len =count ($keywords); $i < $len; $i + +) {$tmp = array (' name ' = = $keywords [$i] [' name '], ' url ' = = $keywords [$i] [' url '], ' brief ' + $TC [$i] [' Brief '], ' News ' = $TC [$i] [' News '], ' tieba ' + $tc [$i] [' Tieba '], ' flag ' + $num [$i] [' flag '], ' num ' + $num [$i] [num ']) ; Array_push ($result, $tmp);} Echo '
   
';p rint_r ($result); Echo '
';? >

After the collection?? The format is as follows:

Array ([0] = = Array ([name] + = haste that year [url] = http://top.baidu.com/detail?b=26&am P;c=1&w=%b4%d2%b4%d2%c4%c7%c4%ea [Brief] = Http://baike.baidu.com/search/word?word=%B4%D2%B4%D2%C4%C7%C 4%ea [News] = Http://news.baidu.com/ns?tn=news&from=news&cl=2&rn=20&ct=1&word=%B4%D2%B4             %d2%c4%c7%c4%ea [Tieba] = Http://tieba.baidu.com/f?kw=%B4%D2%B4%D2%C4%C7%C4%EA [flag] = rise [num] = 162540) [1] = = Array ([name] + a person's martial arts [url] = = http://top.baidu.com/detail?b=26&c=1&w=%D2%BB%B8%F6%C8%CB%B5%C4%CE%E4%C1%D6 [Brief] = Http://baike. BAIDU.COM/SEARCH/WORD?WORD=%D2%BB%B8%F6%C8%CB%B5%C4%CE%E4%C1%D6 [News] = HTTP://NEWS.BAIDU.COM/NS?TN=NEWS&A Mp;from=news&cl=2&rn=20&ct=1&word=%d2%bb%b8%f6%c8%cb%b5%c4%ce%e4%c1%d6 [Tieba] = Http://tie Ba.baidu.com/f?kw=%d2%bb%B8%F6%C8%CB%B5%C4%CE%E4%C1%D6 [flag] = rise [num] = 75428) [2] = = Array ([name] + star crossing [url] = http://top.baidu.com/detail?b=26&c=1&w=%D0%C7%BC%CA%B4%A9% D4%BD [Brief] = Http://baike.baidu.com/search/word?word=%D0%C7%BC%CA%B4%A9%D4%BD [News] + HT TP://NEWS.BAIDU.COM/NS?TN=NEWS&AMP;FROM=NEWS&AMP;CL=2&AMP;RN=20&AMP;CT=1&AMP;WORD=%D0%C7%BC%CA%B4%A9%D4%BD [Tie        BA] = Http://tieba.baidu.com/f?kw=%D0%C7%BC%CA%B4%A9%D4%BD [flag] = rise [num] + 70538 ) [3] = = Array ([name] + ecstatic road put [url] = HTTP://TOP.BAIDU.COM/DETAIL?B=26&A MP;C=1&AMP;W=%D0%C4%BB%A8%C2%B7%B7%C5 [Brief] = http://baike.baidu.com/search/word?word=%D0%C4%BB%A8%C2%B7% B7%C5 [News] = Http://news.baidu.com/ns?tn=news&from=news&cl=2&rn=20&ct=1&word=%D0%C4%B        B%a8%c2%b7%b7%c5    [Tieba] = http://tieba.baidu.com/f?kw=%D0%C4%BB%A8%C2%B7%B7%C5 [flag] = Fall [num] = 68233) ... )

function GetContent modified?.

function GetContent ($url) {$ch = Curl_init (); curl_setopt ($ch, Curlopt_returntransfer, True); curl_setopt ($ch, Curlopt_ URL, $url), curl_setopt ($ch, curlopt_timeout), $response = Curl_exec ($ch), if ($error =curl_error ($ch)) {die ($error) ;} Curl_close ($ch); $content = Iconv (' GB2312 ', ' Utf8//ignore ', $response); return $content;}

The main??? has been Integration??, plus, what do you want to do?

 (.*?) <\/td>/is ', $content, $keywords); $data = $keywords [1]; $result = Array (); foreach ($data as $val) {Preg_match_all ('/ (.*?) <\/a>/is ', $val, $tmp); Array_push ($result, Array (' name ' = = $tmp [2][0], ' url ' = ' http://top.baidu.com '. substr ($tmp [1][0],1));} return $result;} function GETTC ($content) {//Tcpreg_match_all ('/(.*?) <\/td>/is ', $content, $TC); $data = $TC [1]; $result = Array (); foreach ($data as $val) {Preg_match_all ('/(. *?) <\/a>/is ', $val, $tmp); Array_push ($result, Array (' brief ' = $tmp [1][0], ' news ' + $tmp [1][1], ' Tieba ' =>$ TMP[1][2]));} return $result;} function Getnum ($content) {//Lastpreg_match_all ('/(.*?) <\/td>/is ', $content, $last); Icon-rise up Icon-fall down$data = $last [1]; $result = Array (); foreach ($data as $val) {Preg_match_all ('/
 
  
   (.*?) <\/span>/is ', $val, $tmp); Array_push ($result, Array (' Flag ' =>str_replace (' icon-', ' ", $tmp [1][0]), ' num ' = > $tmp [2][0]);} return $result;} $url = ' http://top.baidu.com/buzz?b=26&c=1&fr=topcategory_c1 '; $content = GetContent ($url); $result = Array (); $keywords = GetKeywords ($content), $TC = GETTC ($content), $num = Getnum ($content), for ($i =0, $len =count ($keywords); $i < $len; $i + +) {$tmp = array (' name ' = = $keywords [$i] [' name '], ' url ' = = $keywords [$i] [' url '], ' brief ' + $TC [$i] [' Brief '], ' News ' = $TC [$i] [' News '], ' tieba ' + $tc [$i] [' Tieba '], ' flag ' + $num [$i] [' flag '], ' num ' + $num [$i] [num ']) ; Array_push ($result, $tmp);} Echo '
   
';p rint_r ($result); Echo '
';? >


Why am I testing this array when the output is empty

Is your php file UTF8

Is your php file UTF8


Yes

Why don't you go back to the getcontent and see what's going on?

? and you put???? If white screen, it's??。. Do you have Ann curl?
In the face, plus
Ini_set (' display_errors ', ' on ');
Error_reporting (E_all);
Let's see what??。. If you are prompted for curl?
Can you change getcontent?

function GetContent ($url) {    $response = file_get_contents ($url);//sentence instead of curl     $content = iconv (' GB2312 ', ' utf8// IGNORE ', $response);     return $content;}

There's nothing out there.
It doesn't change the code to ANSI.

Do you test which files are available to package?

Notice:iconv () [Function.iconv]: Wrong charset, conversion from ' GB2312 ' to ' utf8//ignore ' are not allowed in F:\PHPnow-1. 5.6\vhosts\test.php on line 15

$content = Iconv (' GB2312 ', ' UTF-8 ', $response);


That's it.


Question I am a rookie, how to remove this array to normal use?

$content = Iconv (' GBK ', ' Utf-8//ignore ', $response);

Notice:iconv () [Function.iconv]: Wrong charset, conversion from ' GB2312 ' to ' utf8//ignore ' are not allowed in F:\PHPnow-1. 5.6\vhosts\test.php on line 15

$content = Iconv (' GB2312 ', ' Utf8//ignore ', $response);
Change?
$content = Iconv (' GBK ', ' Utf8//ignore ', $response);
??

Get??? I don't know how to use ... Oh.

What do you want to do? HTML, and then, where needed, insert the????。

Array a coincidentally different, depressed

Actually, I just need to be like this.

Hurried that year hastily that year hurried that year hurried that year hurried that year

?? A complete example, Hello good?? Under
What do you want to change, directly change it.

 (.*?) <\/td>/is ', $content, $keywords); $data = $keywords [1]; $result = Array (); foreach ($data as $val) {Preg_match_all ('/ (.*?) <\/a>/is ', $val, $tmp); Array_push ($result, Array (' name ' = = $tmp [2][0], ' url ' = ' http://top.baidu.com '. substr ($tmp [1][0],1));} return $result;} function GETTC ($content) {//Tcpreg_match_all ('/(.*?) <\/td>/is ', $content, $TC); $data = $TC [1]; $result = Array (); foreach ($data as $val) {Preg_match_all ('/(. *?) <\/a>/is ', $val, $tmp); Array_push ($result, Array (' brief ' = $tmp [1][0], ' news ' + $tmp [1][1], ' Tieba ' =>$ TMP[1][2]));} return $result;} function Getnum ($content) {//Lastpreg_match_all ('/(.*?) <\/td>/is ', $content, $last); Icon-rise up Icon-fall down$data = $last [1]; $result = Array (); foreach ($data as $val) {Preg_match_all ('/
 
  (.*?) <\/span>/is ', $val, $tmp); Array_push ($result, Array (' Flag ' =>str_replace (' icon-', ' ", $tmp [1][0]), ' num ' = > $tmp [2][0]);} return $result;} $url = ' http://top.baidu.com/buzz?b=340&c=1&fr=topbuzz_b339_c1 '; $content = GetContent ($url); $result = Array ( ); $keywords = GetKeywords ($content); $TC = GETTC ($content); $num = Getnum ($content); for ($i =0, $len =count ($keywords); $i < $len; $i + +) {$tmp = array (' name ' = = $keywords [$i] [' name '], ' url ' = = $keywords [$i] [' url '], ' brief ' + $TC [$i] [' Brief '], ' News ' = $TC [$i] [' News '], ' tieba ' + $tc [$i] [' Tieba '], ' flag ' + $num [$i] [' flag '], ' num ' + $num [$i] [num ']) ; Array_push ($result, $tmp);}? >   
  
   
    
  <title>Baidu</title>  
  
 
"> "; "> New? "?"
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.