php 生成 google video xml sitemap 过程

  1 <?php
  2 header("Content-Type:text/html;charset:utf-8");
  3 $mysql_server_name='localhost';
  4 $mysql_username='fur168.com';
  5 $mysql_password='fur168.com';
  6 $mysql_database='zhouggdy';
  7 $conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
  8 
  9 //echo unescape($_GET['q']);
 10 
 11 
 12 
 13  // $sql = "select * from gx_video where title like  '%".$_GET['q']."%'";
 14  //echo $sql;
 15 //  $sql = "select * from gx_video";
 16  $sql='select * FROM gx_video where  cid in (8,9,10,12,22) order by addtime desc';
 17 mysql_select_db($mysql_database,$conn);
 18 mysql_query("SET NAMES UTF8");
 19 $result=mysql_query($sql);
 20 
 21 
 22 
 23 
 24 
 25 
 26 $docu=new DOMDocument('1.0','utf-8');//声明DOMDocument对象
 27 
 28 
 29 
 30      $docu->formatOutput=true;//使用xml标准化格式输出
 31 
 32      $urlset=$docu->createElement('urlset');
 33 
 34      $attribute =$docu->createAttribute('xmlns');
 35      $value=$docu->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9');
 36      $attribute->appendChild($value);
 37 
 38      $attribute1 =$docu->createAttribute('xmlns:video');
 39      $value1=$docu->createTextNode('http://www.google.com/schemas/sitemap-video/1.1');
 40      $attribute1->appendChild($value1);
 41 
 42       $urlset->appendChild($attribute);
 43       $urlset->appendChild($attribute1);
 44 
 45 
 46 while($row = mysql_fetch_array($result))
 47  {
 48      $url=$docu->createElement('url');
 49 
 50       $urlset->appendChild($url);
 51 
 52 
 53 
 54      $loc=$docu->createElement('loc');
 55      $value=$docu->createTextNode("http://www.fur168.com/freemoviedetail/".$row['id'].".html");
 56      $loc->appendChild($value);
 57      $url->appendChild($loc);
 58 
 59 
 60 
 61 
 62      $item=$docu->createElement('video:video');
 63 
 64 
 65 
 66 
 67      $thumbnail_loc=$docu->createElement('video:thumbnail_loc');
 68      $value=$docu->createcdatasection("http://www.fur168.com/uploads/".$row['picurl']);
 69      $thumbnail_loc->appendChild($value);
 70      $item->appendChild($thumbnail_loc);
 71 
 72      $title =$docu->createElement('video:title');
 73      $value=$docu->createcdatasection($row['title']);
 74      $title->appendChild($value);
 75      $item->appendChild($title);
 76 
 77      $description  =$docu->createElement('video:description');
 78      $value=$docu->createcdatasection(strip_tags(utf8_CsubStr($row['content'],0,120)));
 79      $description->appendChild($value);
 80      $item->appendChild($description);
 81 
 82      $payarrexplode('$',$row['playurl']);
 83      $payurl="";
 84      $n=count($payarr);
 85 
 86 
 87 
 88 
 89           $temp=explode('rmvb', $payarr[1]);
 90 
 91 
 92          $payurltrim$temp[0].'rmvb');
 93 
 94 
 95       if($payurl=='1rmvb' or $payurl=='rmvb' or $payurl=='DVDrmvb' or $payurl=='bdhdrmvb'  or $payurl=='暂无地址rmvb' )
 96            $payurl='bdhd://348958126|1BAE2436DB45443822D8DEDA95AAD4A8|燃烧弹.rmvb';
 97       if($row['id']=='11645')
 98       {
 99           $payurl='bdhd://'.$payurl;
100       }
101       if($row['id']=='11134' or  $row['id']=='9526' or $row['id']=='7718' or $row['id']=='7001' )
102       {
103          $payurl='bdhd://338288786|7350F431444A75758F51950AE469D24E|aaaji.com复仇威龙.rmvb';
104       }
105 
106     if(!strstr$payurl,'bdhd'))
107            $payurl='bdhd://348958126|1BAE2436DB45443822D8DEDA95AAD4A8|燃烧弹.rmvb';
108 
109      $content_loc=$docu->createElement('video:content_loc');
110      $value=$docu->createcdatasection($payurl);
111      $content_loc->appendChild($value);
112      $item->appendChild($content_loc);
113 
114     if($row['keywords']=="")
115      {
116     $tag   =$docu->createElement('video:tag');
117     $value=$docu->createTextNode($row['title']);
118     $tag->appendChild($value);
119     $item->appendChild($tag);
120      }
121 
122      else
123      {
124 
125     $arr =  explode(',',$row['keywords']);
126     $n=count$arr);
127 
128 
129     for($i=0;$istrlen($n);$i++)
130         {
131 
132             $tag=$docu->createElement('video:tag');
133             $value=$docu->createTextNode( $arr[$i]);
134             $tag->appendChild($value);
135             $item->appendChild($tag);
136         }
137      }
138 
139 
140     $duration  =$docu->createElement('video:duration');
141     $value=$docu->createTextNode(4800);
142     $duration->appendChild($value);
143     $item->appendChild($duration);
144 
145     /*
146     $cdate= date('Y-m-d H:i:s',$row['addtime']);
147     $publication_date =$docu->createElement('video:publication_date');
148     $value=$docu->createTextNode($cdate);
149     $publication_date->appendChild($value);
150     $item->appendChild($publication_date);
151     */
152 
153     $category  =$docu->createElement('video:category');
154     $value=$docu->createTextNode('电影,电视剧');
155     $category->appendChild($value);
156     $item->appendChild($category);
157 
158      $url->appendChild($item);
159 
160      $docu->appendChild($urlset);
161  }
162      mysql_close($conn);
163      $docu->save('googlevideo.xml');//生成xml文件
164 
165 
166 
167 
168 function utf8_CsubStr($str,$start,$len,$suffix='...'){
169     preg_match_all('#(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+)#s',$str,$array, PREG_PATTERN_ORDER);
170     $from1 = 0; $len1 = 0; $s = '';
171     foreach($array[0] as $key => $val){
172         $n = ord($val) >= 128 ? 2 : 1;
173         $from1 += $n;
174         if($from1 > $start){
175             $len1+=$n;
176             if($len1 <= $len$s .= $val;
177             else return $s.$suffix;
178         }
179     }
180     return $s;
181 }
182 
183 
184 ?>

 

貌似,这代码插入功能还不错哟.上段代码有点PHP基础的应该能看懂的.具体效果可以到我的苍井空电影 看看.用谷歌的sitemap管理工具就可以看到已编入 的索引了,不知道会不会来流量,看几天,再告诉大家哟 

posted @ 2012-04-28 21:54  独孤求欢  阅读(633)  评论(0编辑  收藏  举报