PHP抓取、分析国内视频网站的视频信息工具类

VideoUrlParser是一款基于PHP根据视频URL抓取视频信息的工具,支持优酷、土豆、酷六、56、乐视、搜狐、腾讯、新浪。

使用方法:

  1. require_once "VideoUrlParser.class.php";
  2. $url = "http://v.youku.com/v_show/id_XMjkwMzc0Njg4.html";
  3. $info = VedioUrlParser::parse($url);
  4. echo $info;

说明:调用该工具php文件VideoUrlParser.class.php,$url变量后面的字符串为视频页的地址,然后使用echo输出变量$info。

附:info含有的几个值,分别是img(用于视频缩略图),title(视频标题),url(地址),swf(视频swf播放地址)。我只用到了img和swf地址。具体的可以根据自己的需要进行调整。

VideoUrlParser类源码:

  1. <?php
  2. /**
  3. * Video
  4. *
  5. * @package
  6. * @version 1.2
  7. * @copyright 2005-2011 HDJ.ME
  8. * @author Dijia Huang <huangdijia@gmail.com>
  9. * @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
  10. *
  11. * Usage
  12. * require_once "VideoUrlParser.class.php";
  13. * $urls[] = "http://v.youku.com/v_show/id_XMjI4MDM4NDc2.html";
  14. * $urls[] = "http://www.tudou.com/playlist/p/l13087099.html";
  15. * $urls[] = "http://www.tudou.com/programs/view/ufg-A3tlcxk/";
  16. * $urls[] = "http://v.ku6.com/special/show_4926690/Klze2mhMeSK6g05X.html";
  17. * $urls[] = "http://www.56.com/u68/v_NjI2NTkxMzc.html";
  18. * $urls[] = "http://www.letv.com/ptv/vplay/1168109.html";
  19. * $urls[] = "http://video.sina.com.cn/v/b/46909166-1290055681.html";
  20. *
  21. * foreach($urls as $url){
  22. * $info = VideoUrlParser::parse($url);
  23. * //var_dump($info);
  24. * echo "<a href='{$info['url']}' target='_new'>{$info['title']}</a>";
  25. * echo "<br />";
  26. * echo $info['object'];
  27. * echo "<br />";
  28. * }
  29. *
  30. *
  31. *
  32. * //优酷
  33. * http://v.youku.com/v_show/id_XMjU0NjY4OTEy.html
  34. * <embed src="http://player.youku.com/player.php/sid/XMjU0NjY4OTEy/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash"></embed>
  35. *
  36. * //酷六
  37. * http://v.ku6.com/special/show_3917484/x0BMXAbgZdQS6FqN.html
  38. * <embed src="http://player.ku6.com/refer/x0BMXAbgZdQS6FqN/v.swf" quality="high" width="480" height="400" align="middle" allowScriptAccess="always" allowfullscreen="true" type="application/x-shockwave-flash"></embed>
  39. *
  40. * //土豆
  41. * http://www.tudou.com/playlist/p/a65929.html?iid=74905844
  42. * <embed src="http://www.tudou.com/l/A_0urj-Geec/&i type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="opaque" width="480" height="400"></embed>
  43. *
  44. * //56
  45. * http://www.56.com/u98/v_NTkyODY2NTU.html
  46. * <embed src="http://player.56.com/v_NTkyODY2NTU.swf" type="application/x-shockwave-flash" width="480" height="405" allowNetworking="all" allowScriptAccess="always"></embed>
  47. *
  48. * //新浪播客
  49. * http://video.sina.com.cn/v/b/46909166-1290055681.html
  50. * <embed src="http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/v pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="ssss" allowFullScreen="true" allowScriptAccess="always" width="480" height="370"></embed>
  51. *
  52. * //乐视
  53. * http://www.letv.com/ptv/vplay/1168109.html
  54. * <embed src="http://i3.imgs.letv.com/player/swfPlayer.swf? quality="high" scale="NO_SCALE" wmode="opaque" bgcolor="#000000" width="480" height="388" name="FLV_player" align="middle" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
  55. */
  56. class VideoUrlParser
  57. {
  58. const USER_AGENT = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko)
  59. Chrome/8.0.552.224 Safari/534.10";
  60. const CHECK_URL_VALID = "/(youku\.com|tudou\.com|ku6\.com|56\.com|letv\.com|video\.sina\.com\.cn|(my\.)?tv\.sohu\.com|v\.qq\.com)/";
  61. /**
  62. * parse
  63. *
  64. * @param string $url
  65. * @param mixed $createObject
  66. * @static
  67. * @access public
  68. * @return void
  69. */
  70. static public function parse($url='', $createObject=true){
  71. $lowerurl = strtolower($url);
  72. preg_match(self::CHECK_URL_VALID, $lowerurl, $matches);
  73. if(!$matches) return false;
  74. switch($matches[1]){
  75. case 'youku.com':
  76. $data = self::_parseYouku($url);
  77. break;
  78. case 'tudou.com':
  79. $data = self::_parseTudou($url);
  80. break;
  81. case 'ku6.com':
  82. $data = self::_parseKu6($url);
  83. break;
  84. case '56.com':
  85. $data = self::_parse56($url);
  86. break;
  87. case 'letv.com':
  88. $data = self::_parseLetv($url);
  89. break;
  90. case 'video.sina.com.cn':
  91. $data = self::_parseSina($url);
  92. break;
  93. case 'my.tv.sohu.com':
  94. case 'tv.sohu.com':
  95. case 'sohu.com':
  96. $data = self::_parseSohu($url);
  97. break;
  98. case 'v.qq.com':
  99. $data = self::_parseQq($url);
  100. break;
  101. default:
  102. $data = false;
  103. }
  104. if($data && $createObject) $data['object'] = "<embed src=\"{$data['swf']}\" quality=\"high\" width=\"480\" height=\"400\" align=\"middle\" allowNetworking=\"all\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\"></embed>";
  105. return $data;
  106. }
  107. /**
  108. * 腾讯视频
  109. * http://v.qq.com/cover/o/o9tab7nuu0q3esh.html?vid=97abu74o4w3_0
  110. * http://v.qq.com/play/97abu74o4w3.html
  111. * http://v.qq.com/cover/d/dtdqyd8g7xvoj0o.html
  112. * http://v.qq.com/cover/d/dtdqyd8g7xvoj0o/9SfqULsrtSb.html
  113. * http://imgcache.qq.com/tencentvideo_v1/player/TencentPlayer.swf?_v=20110829&vid=97abu74o4w3&autoplay=1&list=2&showcfg=1&tpid=23&title=%E7%AC%AC%E4%B8%80%E7%8E%B0%E5%9C%BA&adplay=1&cid=o9tab7nuu0q3esh
  114. */
  115. private function _parseQq($url){
  116. if(preg_match("/\/play\//", $url)){
  117. $html = self::_fget($url);
  118. preg_match("/url=[^\"]+/", $html, $matches);
  119. if(!$matches); return false;
  120. $url = $matches[0];
  121. }
  122. preg_match("/v, $url, $matches);
  123. $vid = $matches[1];
  124. $html = self::_fget($url);
  125. // query
  126. preg_match("/flashvars\s=\s\"([^;]+)/s", $html, $matches);
  127. $query = $matches[1];
  128. if(!$vid){
  129. preg_match("/vid\s?=\s?vid\s?\|\|\s?\"(\w+)\";/i", $html, $matches);
  130. $vid = $matches[1];
  131. }
  132. $query = str_replace('"+vid+"', $vid, $query);
  133. parse_str($query, $output);
  134. $data['img'] = "http://vpic.video.qq.com/{$$output['cid']}/{$vid}_1.jpg";
  135. $data['url'] = $url;
  136. $data['title'] = $output['title'];
  137. $data['swf'] = "http://imgcache.qq.com/tencentvideo_v1/player/TencentPlayer.swf?".$query;
  138. return $data;
  139. }
  140. /**
  141. * 优酷网
  142. * http://v.youku.com/v_show/id_XMjI4MDM4NDc2.html
  143. * http://player.youku.com/player.php/sid/XMjU0NjI2Njg4/v.swf
  144. */
  145. private function _parseYouku($url){
  146. preg_match("#id\_(\w+)#", $url, $matches);
  147. if (emptyempty($matches)){
  148. preg_match("#v_playlist\/#", $url, $mat);
  149. if(!$mat) return false;
  150. $html = self::_fget($url);
  151. preg_match("#videoId2\s*=\s*\'(\w+)\'#", $html, $matches);
  152. if(!$matches) return false;
  153. }
  154. $link = "http://v.youku.com/player/getPlayList/VideoIDS/{$matches[1]}/timezone/+08/version/5/source/out?password=&ran=2513&n=3";
  155. $retval = self::_cget($link);
  156. if ($retval) {
  157. $json = json_decode($retval, true);
  158. $data['img'] = $json['data'][0]['logo'];
  159. $data['title'] = $json['data'][0]['title'];
  160. $data['url'] = $url;
  161. $data['swf'] = "http://player.youku.com/player.php/sid/{$matches[1]}/v.swf";
  162. return $data;
  163. } else {
  164. return false;
  165. }
  166. }
  167. /**
  168. * 土豆网
  169. * http://www.tudou.com/programs/view/Wtt3FjiDxEE/
  170. * http://www.tudou.com/v/Wtt3FjiDxEE/v.swf
  171. *
  172. * http://www.tudou.com/playlist/p/a65718.html?iid=74909603
  173. * http://www.tudou.com/l/G5BzgI4lAb8/&iid=74909603/v.swf
  174. */
  175. private function _parseTudou($url){
  176. preg_match("#view/([-\w]+)/#", $url, $matches);
  177. if (emptyempty($matches)) {
  178. if (strpos($url, "/playlist/") == false) return false;
  179. if(strpos($url, 'iid=') !== false){
  180. $quarr = explode("iid=", $lowerurl);
  181. if (emptyempty($quarr[1])) return false;
  182. }elseif(preg_match("#p\/l(\d+).#", $lowerurl, $quarr)){
  183. if (emptyempty($quarr[1])) return false;
  184. }
  185. $html = self::_fget($url);
  186. $html = iconv("GB2312", "UTF-8", $html);
  187. preg_match("/lid_code\s=\slcode\s=\s[\'\"]([^\'\"]+)/s", $html, $matches);
  188. $icode = $matches[1];
  189. preg_match("/iid\s=\s.*?\|\|\s(\d+)/sx", $html, $matches);
  190. $iid = $matches[1];
  191. preg_match("/listData\s=\s(\[\{.*\}\])/sx", $html, $matches);
  192. $find = array("/\n/", '/\s/', "/:[^\d\"]\w+[^\,]*,/i", "/(\{|,)(\w+):/");
  193. $replace = array("", "", ':"",', '\\1"\\2":');
  194. $str = preg_replace($find, $replace, $matches[1]);
  195. //var_dump($str);
  196. $json = json_decode($str);
  197. //var_dump($json);exit;
  198. if(is_array($json) || is_object($json) && !emptyempty($json)){
  199. foreach ($json as $val) {
  200. if ($val->iid == $iid) {
  201. break;
  202. }
  203. }
  204. }
  205. $data['img'] = $val->pic;
  206. $data['title'] = $val->title;
  207. $data['url'] = $url;
  208. $data['swf'] = "http://www.tudou.com/l/{$icode}/&i;
  209. return $data;
  210. }
  211. $host = "www.tudou.com";
  212. $path = "/v/{$matches[1]}/v.swf";
  213. $ret = self::_fsget($path, $host);
  214. if (preg_match("#\nLocation: (.*)\n#", $ret, $mat)) {
  215. parse_str(parse_url(urldecode($mat[1]), PHP_URL_QUERY));
  216. $data['img'] = $snap_pic;
  217. $data['title'] = $title;
  218. $data['url'] = $url;
  219. $data['swf'] = "http://www.tudou.com/v/{$matches[1]}/v.swf";
  220. return $data;
  221. }
  222. return false;
  223. }
  224. /**
  225. * 酷6网
  226. * http://v.ku6.com/film/show_520/3X93vo4tIS7uotHg.html
  227. * http://v.ku6.com/special/show_4926690/Klze2mhMeSK6g05X.html
  228. * http://v.ku6.com/show/7US-kDXjyKyIInDevhpwHg...html
  229. * http://player.ku6.com/refer/3X93vo4tIS7uotHg/v.swf
  230. */
  231. private function _parseKu6($url){
  232. if(preg_match("/show\_/", $url)){
  233. preg_match("#/([-\w]+)\.html#", $url, $matches);
  234. $url = "http://v.ku6.com/fetchVideo4Player/{$matches[1]}.html";
  235. $html = self::_fget($url);
  236. if ($html) {
  237. $json = json_decode($html, true);
  238. if(!$json) return false;
  239. $data['img'] = $json['data']['picpath'];
  240. $data['title'] = $json['data']['t'];
  241. $data['url'] = $url;
  242. $data['swf'] = "http://player.ku6.com/refer/{$matches[1]}/v.swf";
  243. return $data;
  244. } else {
  245. return false;
  246. }
  247. }elseif(preg_match("/show\//", $url, $matches)){
  248. $html = self::_fget($url);
  249. preg_match("/ObjectInfo\s?=\s?([^\n]*)};/si", $html, $matches);
  250. $str = $matches[1];
  251. // img
  252. preg_match("/cover\s?:\s?\"([^\"]+)\"/", $str, $matches);
  253. $data['img'] = $matches[1];
  254. // title
  255. preg_match("/title\"?\s?:\s?\"([^\"]+)\"/", $str, $matches);
  256. $jsstr = "{\"title\":\"{$matches[1]}\"}";
  257. $json = json_decode($jsstr, true);
  258. $data['title'] = $json['title'];
  259. // url
  260. $data['url'] = $url;
  261. // query
  262. preg_match("/\"(v]+)\"\sname=\"flashVars\"/s", $html, $matches);
  263. $query = str_replace("&amp;", '&', $matches[1]);
  264. preg_match("/\/\/player\.ku6cdn\.com[^\"\']+/", $html, $matches);
  265. $data['swf'] = 'http:'.$matches[0].'?'.$query;
  266. return $data;
  267. }
  268. }
  269. /**
  270. * 56网
  271. * http://www.56.com/u73/v_NTkzMDcwNDY.html
  272. * http://player.56.com/v_NTkzMDcwNDY.swf
  273. */
  274. private function _parse56($url){
  275. preg_match("#/v_(\w+)\.html#", $url, $matches);
  276. if (emptyempty($matches)) return false;
  277. $link="http://vxml.56.com/json/{$matches[1]}/?src=out";
  278. $retval = self::_cget($link);
  279. if ($retval) {
  280. $json = json_decode($retval, true);
  281. $data['img'] = $json['info']['img'];
  282. $data['title'] = $json['info']['Subject'];
  283. $data['url'] = $url;
  284. $data['swf'] = "http://player.56.com/v_{$matches[1]}.swf";
  285. return $data;
  286. } else {
  287. return false;
  288. }
  289. }
  290. /**
  291. * 乐视网
  292. * http://www.letv.com/ptv/vplay/1168109.html
  293. * http://www.letv.com/player/x1168109.swf
  294. */
  295. private function _parseLetv($url){
  296. $html = self::_fget($url);
  297. preg_match("#http://v.t.sina.com.cn/([^'\"]*)#", $html, $matches);
  298. parse_str(parse_url(urldecode($matches[0]), PHP_URL_QUERY));
  299. preg_match("#vplay/(\d+)#", $url, $matches);
  300. $data['img'] = $pic;
  301. $data['title'] = $title;
  302. $data['url'] = $url;
  303. $data['swf'] = "http://www.letv.com/player/x{$matches[1]}.swf";
  304. return $data;
  305. }
  306. // 搜狐TV http://my.tv.sohu.com/u/vw/5101536
  307. private function _parseSohu($url){
  308. $html = self::_fget($url);
  309. $html = iconv("GB2312", "UTF-8", $html);
  310. preg_match_all("/og:(?:title|image|videosrc)\"\scontent=\"([^\"]+)\"/s", $html, $matches);
  311. $data['img'] = $matches[1][1];
  312. $data['title'] = $matches[1][0];
  313. $data['url'] = $url;
  314. $data['swf'] = $matches[1][2];
  315. return $data;
  316. }
  317. /*
  318. * 新浪播客
  319. * http://video.sina.com.cn/v/b/48717043-1290055681.html
  320. * http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=48717043_1290055681_PUzkSndrDzXK+l1lHz2stqkP7KQNt6nki2O0u1ehIwZYQ0/XM5GdatoG5ynSA9kEqDhAQJA4dPkm0x4/s.swf
  321. */
  322. private function _parseSina($url){
  323. preg_match("/(\d+)(?:\-|\_)(\d+)/", $url, $matches);
  324. $url = "http://video.sina.com.cn/v/b/{$matches[1]}-{$matches[2]}.html";
  325. $html = self::_fget($url);
  326. preg_match("/video\s?:\s?([^<]+)}/", $html, $matches);
  327. $find = array("/\n/", "/\s*/", "/\'/", "/\{([^:,]+):/", "/,([^:]+):/", "/:[^\d\"]\w+[^\,]*,/i");
  328. $replace = array('', '', '"', '{"\\1":', ',"\\1":', ':"",');
  329. $str = preg_replace($find, $replace, $matches[1]);
  330. $arr = json_decode($str, true);
  331. $data['img'] = $arr['pic'];
  332. $data['title'] = $arr['title'];
  333. $data['url'] = $url;
  334. $data['swf'] = $arr['swfOutsideUrl'];
  335. return $data;
  336. }
  337. /*
  338. * 通过 file_get_contents 获取内容
  339. */
  340. private function _fget($url=''){
  341. if(!$url) return false;
  342. $html = file_get_contents($url);
  343. // 判断是否gzip压缩
  344. if($dehtml = self::_gzdecode($html))
  345. return $dehtml;
  346. else
  347. return $html;
  348. }
  349. /*
  350. * 通过 fsockopen 获取内容
  351. */
  352. private function _fsget($path='/', $host='', $user_agent=''){
  353. if(!$path || !$host) return false;
  354. $user_agent = $user_agent ? $user_agent : self::USER_AGENT;
  355. $out = <<<HEADER
  356. GET $path HTTP/1.1
  357. Host: $host
  358. User-Agent: $user_agent
  359. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  360. Accept-Language: zh-cn,zh;q=0.5
  361. Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n\r\n
  362. HEADER;
  363. $fp = @fsockopen($host, 80, $errno, $errstr, 10);
  364. if (!$fp) return false;
  365. if(!fputs($fp, $out)) return false;
  366. while ( !feof($fp) ) {
  367. $html .= fgets($fp, 1024);
  368. }
  369. fclose($fp);
  370. // 判断是否gzip压缩
  371. if($dehtml = self::_gzdecode($html))
  372. return $dehtml;
  373. else
  374. return $html;
  375. }
  376. /*
  377. * 通过 curl 获取内容
  378. */
  379. private function _cget($url='', $user_agent=''){
  380. if(!$url) return;
  381. $user_agent = $user_agent ? $user_agent : self::USER_AGENT;
  382. $ch = curl_init();
  383. curl_setopt($ch, CURLOPT_URL, $url);
  384. curl_setopt($ch, CURLOPT_HEADER, 0);
  385. if(strlen($user_agent)) curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  386. ob_start();
  387. curl_exec($ch);
  388. $html = ob_get_contents();
  389. ob_end_clean();
  390. if(curl_errno($ch)){
  391. curl_close($ch);
  392. return false;
  393. }
  394. curl_close($ch);
  395. if(!is_string($html) || !strlen($html)){
  396. return false;
  397. }
  398. return $html;
  399. // 判断是否gzip压缩
  400. if($dehtml = self::_gzdecode($html))
  401. return $dehtml;
  402. else
  403. return $html;
  404. }
  405. private function _gzdecode($data) {
  406. $len = strlen ( $data );
  407. if ($len < 18 || strcmp ( substr ( $data, 0, 2 ), "\x1f\x8b" )) {
  408. return null; // Not GZIP format (See RFC 1952)
  409. }
  410. $method = ord ( substr ( $data, 2, 1 ) ); // Compression method
  411. $flags = ord ( substr ( $data, 3, 1 ) ); // Flags
  412. if ($flags & 31 != $flags) {
  413. // Reserved bits are set -- NOT ALLOWED by RFC 1952
  414. return null;
  415. }
  416. // NOTE: $mtime may be negative (PHP integer limitations)
  417. $mtime = unpack ( "V", substr ( $data, 4, 4 ) );
  418. $mtime = $mtime [1];
  419. $xfl = substr ( $data, 8, 1 );
  420. $os = substr ( $data, 8, 1 );
  421. $headerlen = 10;
  422. $extralen = 0;
  423. $extra = "";
  424. if ($flags & 4) {
  425. // 2-byte length prefixed EXTRA data in header
  426. if ($len - $headerlen - 2 < 8) {
  427. return false; // Invalid format
  428. }
  429. $extralen = unpack ( "v", substr ( $data, 8, 2 ) );
  430. $extralen = $extralen [1];
  431. if ($len - $headerlen - 2 - $extralen < 8) {
  432. return false; // Invalid format
  433. }
  434. $extra = substr ( $data, 10, $extralen );
  435. $headerlen += 2 + $extralen;
  436. }
  437. $filenamelen = 0;
  438. $filename = "";
  439. if ($flags & 8) {
  440. // C-style string file NAME data in header
  441. if ($len - $headerlen - 1 < 8) {
  442. return false; // Invalid format
  443. }
  444. $filenamelen = strpos ( substr ( $data, 8 + $extralen ), chr ( 0 ) );
  445. if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
  446. return false; // Invalid format
  447. }
  448. $filename = substr ( $data, $headerlen, $filenamelen );
  449. $headerlen += $filenamelen + 1;
  450. }
  451. $commentlen = 0;
  452. $comment = "";
  453. if ($flags & 16) {
  454. // C-style string COMMENT data in header
  455. if ($len - $headerlen - 1 < 8) {
  456. return false; // Invalid format
  457. }
  458. $commentlen = strpos ( substr ( $data, 8 + $extralen + $filenamelen ), chr ( 0 ) );
  459. if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
  460. return false; // Invalid header format
  461. }
  462. $comment = substr ( $data, $headerlen, $commentlen );
  463. $headerlen += $commentlen + 1;
  464. }
  465. $headercrc = "";
  466. if ($flags & 1) {
  467. // 2-bytes (lowest order) of CRC32 on header present
  468. if ($len - $headerlen - 2 < 8) {
  469. return false; // Invalid format
  470. }
  471. $calccrc = crc32 ( substr ( $data, 0, $headerlen ) ) & 0xffff;
  472. $headercrc = unpack ( "v", substr ( $data, $headerlen, 2 ) );
  473. $headercrc = $headercrc [1];
  474. if ($headercrc != $calccrc) {
  475. return false; // Bad header CRC
  476. }
  477. $headerlen += 2;
  478. }
  479. // GZIP FOOTER - These be negative due to PHP's limitations
  480. $datacrc = unpack ( "V", substr ( $data, - 8, 4 ) );
  481. $datacrc = $datacrc [1];
  482. $isize = unpack ( "V", substr ( $data, - 4 ) );
  483. $isize = $isize [1];
  484. // Perform the decompression:
  485. $bodylen = $len - $headerlen - 8;
  486. if ($bodylen < 1) {
  487. // This should never happen - IMPLEMENTATION BUG!
  488. return null;
  489. }
  490. $body = substr ( $data, $headerlen, $bodylen );
  491. $data = "";
  492. if ($bodylen > 0) {
  493. switch ($method) {
  494. case 8 :
  495. // Currently the only supported compression method:
  496. $data = gzinflate ( $body );
  497. break;
  498. default :
  499. // Unknown compression method
  500. return false;
  501. }
  502. } else {
  503. //...
  504. }
  505. if ($isize != strlen ( $data ) || crc32 ( $data ) != $datacrc) {
  506. // Bad format! Length or CRC doesn't match!
  507. return false;
  508. }
  509. return $data;
  510. }
  511. }