where My_encoding () is converted into the way you want to encode! I novice a little trick master laughed at!
- ?
- function Get_sub_content ($str, $start, $end) {
- if ($start = = ' $end = = ') {
- Return page element has changed! ";
- }
- $str = Explode ($start, $str);
- $str = Explode ($end, $str [1]);
- return $str [0];
- }
- function my_encoding ($data, $to) {
- $encode _arr = Array (' UTF-8 ', ' ASCII ', ' GBK ', ' GB2312 ', ' BIG5 ', ' JIS ', ' Eucjp-win ', ' Sjis-win ', ' euc-jp ');
- $encoded = mb_detect_encoding ($data, $encode _arr);
- $data = mb_convert_encoding ($data, $to, $encoded);
- return $data;
- }
- $doc = file_get_contents ("http://video.baidu.com/v?ct=0&word= Jay%20site%3awww%2etudou%2ecom&db=0&ty= 0&rn=20&pn=0&fbl=1024 ");
- $doc = my_encoding ($doc, "utf-8");
- $doc =get_sub_content ($doc, "<div id=\" result\ ">", "<br clear=");
- $str _replace = Explode ("<div class=x>", $doc);
- echo "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>";
- echo "<data>";
- For ($i =1 $i <=count ($str _replace)-1; $i + +) {
- echo "<video>";
- echo "<name>";
- echo "<! [cdata[". Get_sub_content ($str _replace[$i]," title=\ "", "\"). "] > ";
- echo "</name>";
- echo "<pageurl>";
- echo "<! [cdata[. Get_sub_content ($str _replace[$i], "<a href=\" "," \ "onmousedown=").] > ";
- echo "</pageurl>";
- echo "</video>";
- }
- echo "</data>";
- ?>