最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > 建站教程 > php教程 >

一款实用php 正则文件扩展名代码

时间:2014-06-09 16:40来源: 作者: 点击: 次
*/ function attachicon( $type , $size = ){ static $attachicons = array ( 0= common.gif , 1= image.gif , 2= binary.gif , 3= rar.gif , 4= msoffice.gif , 5= text.gif , 6= html.gif , 7= real.gif , 8= av.gif , 9= flash.gif , 10= pdf.gif , 11= torrent.gif
  1. */ 
  2. function attachicon($type,$size='') { 
  3.  static $attachicons = array( 
  4.  0 => 'common.gif', 
  5.  1 => 'image.gif', 
  6.  2 => 'binary.gif', 
  7.  3 => 'rar.gif', 
  8.  4 => 'msoffice.gif', 
  9.  5 => 'text.gif', 
  10.  6 => 'html.gif', 
  11.  7 => 'real.gif', 
  12.  8 => 'av.gif', 
  13.  9 => 'flash.gif', 
  14.  10 => 'pdf.gif', 
  15.  11 => 'torrent.gif' 
  16.  ); 
  17.  
  18.  if(preg_match("/image|^(jpg|gif|png|bmp)/", $type)) { 
  19.   $typeid = 1; 
  20.  } elseif(preg_match("/bittorrent|^torrent/", $type)) { 
  21.   $typeid = 11; 
  22.  } elseif(preg_match("/pdf|^pdf/", $type)) { 
  23.   $typeid = 10; 
  24.  } elseif(preg_match("/flash|^(swf|fla|swi)/", $type)) { 
  25.   $typeid = 9; 
  26.  } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)/", $type)) { 
  27.   $typeid = 8; 
  28.  } elseif(preg_match("/real|^(rm|rv)/", $type)) { 
  29.   $typeid = 7; 
  30.  } elseif(preg_match("/htm|^(php|js|pl|cgi|asp教程)/", $type)) { 
  31.   $typeid = 6; 
  32.  } elseif(preg_match("/text|^(txt|rtf|wri|chm)/", $type)) { 
  33.   $typeid = 5; 
  34.  } elseif(preg_match("/word|powerpoint|^(doc|ppt)/", $type)) { 
  35.   $typeid = 4; 
  36.  } elseif(preg_match("/compressed|^(zip|arj|rar|arc|cab|lzh|lha|tar|gz)/", $type)) { 
  37.   $typeid = 3; 
  38.  } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)/", $type)) { 
  39.   $typeid = 2; 
  40.  } else { 
  41.   $typeid = 0; 
  42.  } 
  43.  return $size.$attachicons[$typeid]; 
  44. } 
(责任编辑:admin)
------分隔线----------------------------
栏目列表
推荐内容