国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁(yè) 後端開(kāi)發(fā) php教程 php 使用PHPEXcel匯出表格數(shù)據(jù)

php 使用PHPEXcel匯出表格數(shù)據(jù)

Jul 25, 2016 am 08:41 AM

專(zhuān)案中需要將表格中的資料匯出,網(wǎng)路上找了找發(fā)現(xiàn)phpexcel蠻好用的.特此分享

PHPEXCEL

  1. if(!defined('BASEPATH')) exit('No direct script access allowed');//物資發(fā)料>//物資發(fā)料單明細(xì)
  2. class Read_write{
  3. /**
  4. * $name:選擇的類(lèi)型(CSV,EXCEL2003,2007)
  5. * $titles:標(biāo)題數(shù)組
  6. * $querys:查詢(xún)傳回的陣列$query->result_array();
  7. * $ filename:儲(chǔ)存的檔案名稱(chēng)
  8. */
  9. function write_Factory($titles,$querys,$filename,$name="EXCEL2003"){
  10. $CI = &get_instance();
  11. $filename=mb_convert_encoding($filename, "GBK","UTF-8");
  12. switch ($name) {
  13. case "CSV":
  14. $CI->excel->write_CSV($titles,$querys,$filename);
  15. break;
  16. case "EXCEL2003":
  17. $CI->excel->write_EXCEL2003($titles,$querys, $filename);
  18. break;
  19. case "EXCEL2007":
  20. $CI->excel->write_EXCEL2007($titles,$querys,$filename);
  21. break;
  22. }
  23. }
  24. /**
  25. * $名稱(chēng):
  26. */
  27. function read_Facotry($filePath,$sql,$sheet=0,$curRow=2,$riqi=TRUE,$merge=FALSE,$mergeCol ="B"){
  28. $CI = &get_instance();
  29. $name=$this->_file_extend($filePath);
  30. switch ($name) {
  31. case "csv":
  32. $CI->excel->read_CSV($filePath,$sql,$sheet,$curRow,$riqi,$merge,$mergeCol);
  33. break;
  34. case "xls":
  35. $ CI->excel->read_2003Excel($filePath,$sql,$sheet,$curRow,$riqi,$merge,$mergeCol);
  36. break;
  37. case "xlsx":
  38. $CI-> excel->read_EXCEL2007($filePath,$sql,$sheet,$curRow,$riqi,$merge,$mergeCol);
  39. break;
  40. }
  41. $CI->mytool->import_info("filePath =$filePath,sql=$sql");
  42. }
  43. /**
  44. * 2012-1-14 讀取工作薄名稱(chēng)(sheetnames)
  45. */
  46. function read_sheetNames($filePath){
  47. $CI = &get_instance();
  48. $ name=$this->_file_extend($filePath);
  49. $sheetnames;
  50. switch ($name) {
  51. case "csv":
  52. $sheetnames=$CI->excel->read_CSV_Sheet( $filePath);
  53. break;
  54. case "xls":
  55. $sheetnames=$CI->excel->read_2003Excel_Sheet($filePath);
  56. break;
  57. case "xlsx"
  58. $sheetnames=$CI->excel->read_EXCEL2007_Sheets($filePath);
  59. break;
  60. }
  61. return $sheetnames;
  62. }
  63. //讀取檔案後綴名
  64. function _file_extend($file_name){
  65. $extend =explode("." , $file_name);
  66. $last=count($extend)-1;
  67. return $extend[$last];
  68. }
  69. //-------------------------------------------------- -----預(yù)備保留
  70. //2011-12-21新增CVS匯出功能
  71. public function export_csv($filename,$title,$datas, $delim = ",", $newline = "n ", $enclosure = '"'){
  72. $CI = &get_instance();
  73. $cvs= $this->_csv_from_result($title,$datas,$delim,$newline,$enclosure);
  74. $CI->load->helper('download');
  75. $name=mb_convert_encoding($filename, "GBK","UTF-8");
  76. force_download($name, $cvs);
  77. }
  78. /**
  79. * @param $titles:標(biāo)題
  80. * @param $datas:資料
  81. */
  82. function _csv_from_result($titles,$datas, $delim = ",", $newline = "n", $enclosure = '"'){
  83. $out = '';
  84. // First generate the headings from the table column names
  85. foreach ($titles as $name){
  86. $name=mb_convert_encoding($name, "GBK","UTF -8");
  87. $out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim;
  88. }
  89. $out = rtrimim;
  90. }
  91. $out = rtrim ($out);
  92. $out .= $newline;
  93. // Next blast through the result array and build out the rows
  94. foreach ($datas as $row)
  95. { foreach ($row as $item)
  96. {
  97. $item=mb_convert_encoding($item, "GBK","UTF-8");
  98. $out .= $enclosure.str_replace($enclosure, $enclosure .$enclosure, $item).$enclosure.$delim;
  99. }
  100. $out = rtrim($out);
  101. $out .= $newline;
  102. }
  103. return $out;
  104. }
}
複製程式碼

PHPEXCEL?~?13KB????下載(28)

  1. /**
  2. * PHPExcel
  3. *
  4. * 版權(quán)所有(C) 2006 - 2010 PHPExcel
  5. *
  6. * 該函式庫(kù)是免費(fèi)軟體;您可以重新散佈它和/或
  7. * 根據(jù)GNU Lesser General Public 的條款修改它
  8. * 由自由軟體基金會(huì)發(fā)布的授權(quán);
  9. * 授權(quán)的2.1 版,或(由您選擇)任何更高版本。
  10. *
  11. * 分發(fā)此程式庫(kù)的目的是希望它有用,
  12. * 但不提供任何保證;甚至沒(méi)有默示保證
  13. *適銷(xiāo)性或特定用途的適用性。 請(qǐng)參閱 GNU
  14. * 較小通用公共授權(quán)以了解更多詳細(xì)資訊。
  15. *
  16. * 您應(yīng)該已收到GNU 小通用公共許可證
  17. * 與此庫(kù)一起的許可證;如果沒(méi)有,請(qǐng)寫(xiě)信給自由軟體
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. * @category PHPExcel
  21. * @package PHPExcel
  22. * @copyright 版權(quán)所有(c) 2006 - 2010 cel /www.codeplex.com/PHPExcel)
  23. * @license http://www.gnu.org/licenses/old-licenses/lgpl- 2.1.txt LGPL
  24. * @版本1.7.4, 2010-08 -26
  25. */
  26. /**錯(cuò)誤報(bào)告*/
  27. error_reporting(E_ALL);
  28. date_default_timezone_set('預(yù)設(shè)/預(yù)設(shè)');
  29. /**PHPExcel*/
  30. require_once 'Classes/PHPExcel.php';
  31. require_once 'Classes/PHPExcel/IOy.';
  32. require_once 'Classes/PHPExcel/IOy.';
  33. require_once 'Classes/PHPExcel/IOy.';
  34. require_once 'Classes/PHPExcel/IOy.';
  35. require_once 'Classes/PHPExcel/IOy.'PExcel/IOphp;
  36. /**
  37. * 輸出到頁(yè)面上的EXCEL
  38. */
  39. /**
  40. * CI_Excel
  41. *
  42. * @package ci
  43. * @author admin
  44. * @copyright 2011
  45. * @version $Id$
  46. * @access public
  47. * @version $Id$
  48. * @access public
  49. * @version $Id$
  50. * @access public
  51. * @version $Id$
  52. * @access public
  53. * @version $Id$
  54. * @access public
  55. */
  56. class CI_Excel
  57. {
  58. //指定,ExcelOriginalSpecification
  59. private $ cellArray = array (
  60. 1=>'A', 2=>'B', 3=>'C', 4=>'D', 5=>'E',
  61. 6=>'F ', 7=>' G', 8=>'H', 9=>'I',10=>'J',
  62. 11=>'K',12=>'L',13=>'M',14= >'N',15=>'O',
  63. 16=>'P',17=>'Q',18=>'R',19=>'S',2 =>'T',
  64. 21=>'U',22=>'V',23=>'W',24=>'X',25=>'Y',
  65. 26=>'Z',
  66. 27=>'AA', 28=>'AB', 29=>'AC', 30=>'AD', 31=>'AE',
  67. 32=>'AF', 33=>' AG', 34=>'啊', 35=>'AI',36=>'AJ',
  68. 37=>'AK',38=>'AL',39=>'AM',40= >'AN',41=>'AO',
  69. 42=>'AP',43=>'AQ',44=>'AR',45=>'AS',4 =>'AT',
  70. 47=>'AU',48=>'AV',49=>'是',50=>'AX',51=>'否',
  71. 52 => 'AZ', 53= >'BA', 54=>'BB', 55=>'BC', 56=>'BD', 57=>'BE',
  72. 58=>'BF', =>'BG', 60 =>'BH', 61=>'BI', 62=>'BJ', 63=>'BK', 64=>'BL'); E2003';
  73. private $E2007 = 'E2007';
  74. 私人$ECSV = 'ECSV';
  75. 私人$tempName; //指定特定類(lèi)型,產(chǎn)生預(yù)設(shè)值,產(chǎn)生預(yù)設(shè)值
  76. /*********************************匯出資料開(kāi)始**************** ************************************/
  77. /** * 產(chǎn)生Excel2007檔案*/ function write_EXCEL20 07( $title=' ',$data ='',$name='') { $objPHPExcel=$this->_excelComm($title,$data='',$name); //將Application基於網(wǎng)頁(yè)設(shè)計(jì)器(Excel 2007) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'); 版面: Open;filename=$name.xlsx") ; header('Cache-Control: max-age=0'); ") ; $objWriter->save('php://output'); //output 是 print() 和 echo() 方法的預(yù)設(shè)值。
  78. exit;
  79. }
  80. /**
  81. * 產(chǎn)生Excel2003檔
  82. */
  83. function write_EXCEL2003($title='',$data='',$name=''){
  84. $objPHPExcel=$this->_excelComm($title,$data,$name);
  85. // 將輸出重新導(dǎo)向到客戶(hù)端的Web 瀏覽器(Excel5)
  86. header('Content-Type: application/ vnd. ms-excel;charset=UTF-8');
  87. header("Content-Disposition:attachment;filename=$name.xls");
  88. header('Cache-Control: max-age=0 ') ;
  89. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  90. $objWriter->save('php://output');
  91. }
  92. }
  93. /**
  94. * 產(chǎn)生CSV檔
  95. */
  96. function write_CSV($title='',$data='',$name=''){
  97. $objPHPExcel=$this->_excelComm($title ,$data,$name);
  98. header("Content-Type: text/csv;charset=UTF-8");
  99. header("內(nèi)容處置:附件;檔案名稱(chēng)=$name. csv");
  100. header('Cache-Control:必須重新驗(yàn)證,post-check=0,pre-check=0');
  101. header('過(guò)期時(shí)間:0');
  102. header( 'Pragma:public');
  103. $objWriter = new PHPExcel_Writer_CSV($objPHPExcel,'CSV');
  104. $objWriter->save("php://output");
  105. exit;
  106. function _excelComm($title,$data,$name){
  107. // 建立新的PHPExcel 物件
  108. $objPHPExcel = new PHPExcel();
  109. $objPHPExcel=$this- >_writeTitle($title, $objPHPExcel);
  110. $objPHPExcel=$this->_writeDatas($data,$objPHPExcel);
  111. $objPHPExcel=$this->_write_comm($name,$objPHPexcel); > return $objPHPExcel ;
  112. }
  113. // 輸出標(biāo)題
  114. function _writeTitle($title,$objPHPExcel){
  115. //表頭循環(huán)(標(biāo)題) $tkey = $tkey 1;
  116. $cell = $this->cellArray[$tkey].'1'; //第$tkey欄的第1行,列的識(shí)別碼(a..z)
  117. // 增加一些資料//表頭
  118. // $tvalue=mb_convert_encoding($tvalue, "UTF-8 ","GBK");
  119. $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cell, $tvalue); //設(shè)定第$row列的值(標(biāo)題)
  120. }
  121. return $objPHPExcel;
  122. }
  123. / /輸出內(nèi)容
  124. function _writeDatas($data,$objPHPExcel){
  125. //內(nèi)容循環(huán)(資料庫(kù)查詢(xún)的回傳值)
  126. foreach($data as $key =>$value) {
  127. $ i = 1;
  128. foreach ($value as $mkey =>$ mvalue){ //回傳的型別是array([0]=>array());,所以這裡要循環(huán)它的值,如果裡面的array
  129. $rows = $key 2; //開(kāi)始是第二行
  130. $mrow = $this->cellArray[$i].$rows; //第$i列的第$row行
  131. // $mvalue=mb_convert_encoding($mvalue, "GBK","UTF-8");
  132. // print_r($mrow."---> ;".$mvalue);
  133. $objPHPExcel->setActiveSheetIndex(0)->setCellValueExplicit($mrow, $mvalue);
  134. $i ;
  135. }
  136. }
  137. return $objPHPHPExcel>; function _write_comm($name,$objPHPExcel){
  138. // 重新命名sheet(左下角的標(biāo)題)
  139. // $objPHPExcel->getActiveSheet()->setTitle($name);
  140. // 將活動(dòng)工作表索引設(shè)定為第一個(gè)工作表,因此Excel 將其作為第一個(gè)工作表開(kāi)啟
  141. $objPHPExcel->setActiveSheetIndex(0 ); // 預(yù)設(shè)顯示
  142. return $objPHPExcel;
  143. }
  144. /*********************************匯出資料結(jié)束**************** ************************************/
  145. /*********************************讀取資料開(kāi)始****************** *************************************/
  146. /**
  147. * 使用方法,$insertSql:insert xx (x1,x2,x3,x4) value (
  148. */
  149. // 函數(shù)_comm_insert($objReader , $filePath,$insertSql,$sheet=2,$curRow=2,$riqi=TRUE){
  150. 函數(shù)_comm_insert($objPHPExcel,$insertSql,$curRow,$merge=FALSE,$mergeCol='B' ) {
  151. $CI = &get_instance();
  152. $currentSheet = $objPHPExcel->getSheet();//取得指定的啟動(dòng)
  153. /**取得一共有多少列*/
  154. $allColumn = $ currentSheet ->getHighestColumn();
  155. /**取得一共有多少行*/
  156. $allRow = $currentSheet->getHighestRow();
  157. $size=strlen($allColumn);//如果超出Z,則出現(xiàn)不執(zhí)行下去
  158. $esql="";
  159. for($currentRow = $curRow;$currentRow $sql=$insertSql;
  160. if($size==2){
  161. $i=1;
  162. $currentColumn='A';
  163. while ($i $address = $currentColumn.$currentRow;
  164. $temp=$currentSheet->getCell($address)->getCalculatedValue();
  165. $sql. ='"'.$temp.'"'.",";
  166. $currentColumn ;
  167. $i ;
  168. }
  169. for($currentColumn='AA';$currentColumn $address = $currentColumn.$currentRow;
  170. $sql.='"'.$currentSheet->getCell($address)->getCalculatedValue().'"'." ," ;
  171. }
  172. }else{
  173. for($currentColumn='A';$currentColumn if($merge){//如果是$currentColumn ){
  174. if($merge){//如果是讀取合併的值,則判斷,如果此行的值為NULL,則把前面的tempName賦值給$temp; if($currentColumn==$mergeCol){//這裡先指定從B列的名稱(chēng)開(kāi)始讀取合併的值。
  175. $temp=$currentSheet->getCell($mergeCol.$currentRow)->getCalculatedValue();
  176. if(empty($temp)){
  177. $temp=$this->tempName ;
  178. }else{
  179. $this->tempName=$temp;
  180. }
  181. }else{
  182. $address = $currentColumn.$currentRow;//getValue()
  183. $temp=$ currentSheet->getCell($address)->getCalculatedValue();
  184. }
  185. }else{
  186. $address = $currentColumn.$currentRow;//getValue()
  187. $temp=$currentSheet->getCell($address)->getCalculated();
  188. }
  189. $sql=$sql.'"'.$temp.'"'.",";
  190. }
  191. }
  192. $esql=rtrim($sql,"," ).')';
  193. //echo($esql);
  194. //return;
  195. $CI->db->simple_query($esql);
  196. }
  197. }
  198. }
  199. /**
  200. * $filePath:讀取檔案的路徑
  201. * $insertSql:拼字的SQL
  202. */
  203. function read_EXCEL2007($filePath,$insertSql,$sheet=0,$curRow=2,$riqi=TRUE,$merge=FALSE,$mergeCol="B") {
  204. $objs=$this->_get_PHPExcel($this->E2007,$filePath,$sheet,$insertSql,$riqi);
  205. $this->_comm_insert($objs["EXCEL" ],$objs[ "SQL"],$curRow,$merge,$mergeCol);
  206. }
  207. /**
  208. * 讀取2003Excel
  209. */
  210. function read_2003Excel($filePath,$insertSql,$sheet=0,$curRow=2,$riqi=TRUE,$merge=FALSE,$merge= "B"){
  211. $objs=$this->_get_PHPExcel($this->E2003,$filePath,$sheet,$insertSql,$riqi);
  212. $this->_comm_insert($objs ["EXCEL "],$objs["SQL"],$curRow,$merge,$mergeCol);
  213. }
  214. /**
  215. * 讀取CSV
  216. */
  217. function read_CSV($filePath,$insertSql,$sheet=0,$curRow=2,$riqi=TRUE,$merge=FALSE,$merge= "B"){
  218. $objs=$this->_get_PHPExcel($this->ECSV,$filePath,$sheet,$insertSql,$riqi,$mergeCol);
  219. $this->_comm_insert ($objs ["EXCEL"],$objs["SQL"],$curRow,$merge);
  220. }
  221. //--------------------------------讀取工作薄資訊開(kāi)始
  222. /**
  223. * 讀取Excel2007工作薄名
  224. */
  225. function read_EXCEL2007_Sheets($filePath){
  226. return $this->_get_sheetnames($this->E2007,$filePath);
  227. }
  228. }
  229. * 讀取2003Excel工作薄名稱(chēng)
  230. */
  231. function read_2003Excel_Sheet($filePath){
  232. return $this->_get_sheetnames($this->E2003,$filePath);
  233. }
  234. /**>??> /
  235. function read_CSV_Sheet($filePath){
  236. return $this->_get_sheetnames($this->ECSV,$filePath);
  237. }
  238. //---- ------ ----------------------讀取工作薄資訊結(jié)束
  239. /**
  240. * 讀取CSV工作薄名稱(chēng)
  241. */
  242. //讀取Reader流
  243. function _get_Reader($name){
  244. $reader=null;
  245. switch ($name) {
  246. case $this->E2003:
  247. $reader = new PHPExcel_Reader_Excel5 (); 案例$this->E2007:
  248. $reader = new PHPExcel_Reader_Excel2007();
  249. 中斷;
  250. 案例$this->ECSV:
  251. $ reader = new??> 案例$this->ECSV:
  252. $ reader = new PHPcm. > break;
  253. }
  254. return $reader;
  255. }
  256. //取得$objPHPExcel檔案物件
  257. function _get_PHPExcel($name,$filePath,$sheet,$insertSql,$riqi){
  258. $reader=$this->_get_Reader($name);
  259. $PHPExcel= $this->_init_Excel($reader,$filePath,$sheet);
  260. if($riqi){ //如果不需要日期,則忽略。
  261. }
  262. return array("EXCEL"=>$PHPExcel,"SQL"=>$insertSql);
  263. }
  264. //取得工作薄名稱(chēng)
  265. function _get_sheetnames($名稱(chēng),$filePath){
  266. $reader=$this->_get_Reader($name);
  267. $this->_init_Excel($reader, $filePath);
  268. return $reader->getAllSheets();
  269. }
  270. //載入檔案
  271. function _init_Excel($objReader,$filePath,$sheet=''){
  272. $objReader->setReadDataOnly(true);
  273. if(!empty( $sheet)){
  274. $objReader->setSheetIndex($sheet);//讀取第幾個(gè)Sheet。
  275. }
  276. return $objReader->load("$filePath");
  277. }
  278. //--------------------- ----------2012-1-14
  279. }
  280. /*********************************讀取資料結(jié)束****************** *************************************/
複製程式碼

[PHP]代碼

  1. ------------------------導(dǎo)入操作------------ ------------
  2. /**
  3. * $sql="INSERT INTO ".mymsg::WY_MMB." (dizhi,xingming) VALUES (";
  4. */
  5. //先上傳再讀取檔案
  6. function upByFile($sql, $url, $curRow = 2 , $RIQI = true,$merge = FALSE,$mergeCol='B')
  7. {
  8. $CI = &get_instance();
  9. $config['allowed_types'] = '*'; //充許可所有檔案
  10. $config['upload_path'] = IMPORT; // 只在檔案的路徑
  11. $CI->load->library('upload', $config);
  12. if ($CI->upload->do_upload()) { //預(yù)設(shè)名稱(chēng)是:userfile
  13. $data = $CI->upload->data();
  14. $full_name = $ data['full_path']; //得到儲(chǔ)存後的路徑
  15. $full_name = mb_convert_encoding($full_name, "GBK", "UTF-8");
  16. $sheet = $CI->input->post ("sheet"); //讀取第x列圖表
  17. if (empty($sheet)) {
  18. $sheet = 0;
  19. }
  20. $CI->read_write- >read_Facotry($full_name, $sql, $sheet, $curRow, $RIQI,$merge,$mergeCol); //執(zhí)行插入指令
  21. }
  22. $this->alert_msg(mymsg ::IMPORT_SUCCESS, site_url($url));
  23. }
  24. ----------------------------- -匯出操作----------------------------------
  25. //匯出指定的表格欄位
  26. public function show_export(){
  27. //-----資料庫(kù)欄位
  28. $field=implode(",",$this->input->post("listCheckBox_show"));//資料庫(kù)欄位
  29. //顯示名稱(chēng)
  30. $titleArray=$this->input->post("listCheckBox_field");//顯示的欄位名稱(chēng)(欄位Comment註解名稱(chēng),因?yàn)閭鬟M(jìn)來(lái)的有些空數(shù)組,所以必須過(guò)濾)
  31. $title=array();
  32. foreach ($titleArray as $key => $value) {
  33. if (!empty($value)) {
  34. $title[]=$value;
  35. }
  36. }
  37. //---資料庫(kù)表名
  38. $table=$this->input->post("tableName");
  39. //--資料庫(kù)表名稱(chēng)( Comment註解)
  40. $show_name=$this->input->post("tableComment");
  41. //--匯出型別
  42. $type=$this->input->post("type" );
  43. //--where 年月
  44. $y_month=$this->input->post("year_month");
  45. if(!empty($y_month)){
  46. $where["riqi"]=$y_month;
  47. $datas=$this->mcom_model->queryByWhereReField($field,$where,$table);
  48. }else{
  49. //--寫(xiě)出的資料
  50. $datas=$this->mcom_model->queryByField($field,$table);
  51. }
  52. //---開(kāi)始匯出
  53. $this-> read_write->write_Factory($title,$datas,$show_name,$type);
  54. }
複製程式碼

php, PHPEXcel


本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線(xiàn)上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開(kāi)發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

熱門(mén)話(huà)題

如何在PHP中實(shí)施身份驗(yàn)證和授權(quán)? 如何在PHP中實(shí)施身份驗(yàn)證和授權(quán)? Jun 20, 2025 am 01:03 AM

tosecurelyhandleauthenticationandationallizationInphp,lofterTheSesteps:1.AlwaysHashPasswordSwithPassword_hash()andverifyusingspasspassword_verify(),usepreparedStatatementStopreventsqlineptions,andStoreSeruserDatain usseruserDatain $ _sessiveferterlogin.2.implementrole-2.imaccessccsccccccccccccccccccccccccc.

如何在PHP中安全地處理文件上傳? 如何在PHP中安全地處理文件上傳? Jun 19, 2025 am 01:05 AM

要安全處理PHP中的文件上傳,核心在於驗(yàn)證文件類(lèi)型、重命名文件並限制權(quán)限。 1.使用finfo_file()檢查真實(shí)MIME類(lèi)型,僅允許特定類(lèi)型如image/jpeg;2.用uniqid()生成隨機(jī)文件名,存儲(chǔ)至非Web根目錄;3.通過(guò)php.ini和HTML表單限製文件大小,設(shè)置目錄權(quán)限為0755;4.使用ClamAV掃描惡意軟件,增強(qiáng)安全性。這些步驟有效防止安全漏洞,確保文件上傳過(guò)程安全可靠。

PHP中==(鬆散比較)和===(嚴(yán)格的比較)之間有什麼區(qū)別? PHP中==(鬆散比較)和===(嚴(yán)格的比較)之間有什麼區(qū)別? Jun 19, 2025 am 01:07 AM

在PHP中,==與===的主要區(qū)別在於類(lèi)型檢查的嚴(yán)格程度。 ==在比較前會(huì)進(jìn)行類(lèi)型轉(zhuǎn)換,例如5=="5"返回true,而===要求值和類(lèi)型都相同才會(huì)返回true,例如5==="5"返回false。使用場(chǎng)景上,===更安全應(yīng)優(yōu)先使用,==僅在需要類(lèi)型轉(zhuǎn)換時(shí)使用。

如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作? 如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作? Jun 19, 2025 pm 05:13 PM

PHP中使用基本數(shù)學(xué)運(yùn)算的方法如下:1.加法用 號(hào),支持整數(shù)和浮點(diǎn)數(shù),也可用於變量,字符串?dāng)?shù)字會(huì)自動(dòng)轉(zhuǎn)換但不推薦依賴(lài);2.減法用-號(hào),變量同理,類(lèi)型轉(zhuǎn)換同樣適用;3.乘法用*號(hào),適用於數(shù)字及類(lèi)似字符串;4.除法用/號(hào),需避免除以零,並註意結(jié)果可能是浮點(diǎn)數(shù);5.取模用%號(hào),可用於判斷奇偶數(shù),處理負(fù)數(shù)時(shí)餘數(shù)符號(hào)與被除數(shù)一致。正確使用這些運(yùn)算符的關(guān)鍵在於確保數(shù)據(jù)類(lèi)型清晰並處理好邊界情況。

如何與PHP的NOSQL數(shù)據(jù)庫(kù)(例如MongoDB,Redis)進(jìn)行交互? 如何與PHP的NOSQL數(shù)據(jù)庫(kù)(例如MongoDB,Redis)進(jìn)行交互? Jun 19, 2025 am 01:07 AM

是的,PHP可以通過(guò)特定擴(kuò)展或庫(kù)與MongoDB和Redis等NoSQL數(shù)據(jù)庫(kù)交互。首先,使用MongoDBPHP驅(qū)動(dòng)(通過(guò)PECL或Composer安裝)創(chuàng)建客戶(hù)端實(shí)例並操作數(shù)據(jù)庫(kù)及集合,支持插入、查詢(xún)、聚合等操作;其次,使用Predis庫(kù)或phpredis擴(kuò)展連接Redis,執(zhí)行鍵值設(shè)置與獲取,推薦phpredis用於高性能場(chǎng)景,Predis則便於快速部署;兩者均適用於生產(chǎn)環(huán)境且文檔完善。

我如何了解最新的PHP開(kāi)發(fā)和最佳實(shí)踐? 我如何了解最新的PHP開(kāi)發(fā)和最佳實(shí)踐? Jun 23, 2025 am 12:56 AM

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

什麼是PHP,為什麼它用於Web開(kāi)發(fā)? 什麼是PHP,為什麼它用於Web開(kāi)發(fā)? Jun 23, 2025 am 12:55 AM

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

如何設(shè)置PHP時(shí)區(qū)? 如何設(shè)置PHP時(shí)區(qū)? Jun 25, 2025 am 01:00 AM

tosetTherightTimeZoneInphp,restate_default_timezone_set()functionAtthestArtofyourscriptWithavalIdidentIdentifiersuchas'america/new_york'.1.usedate_default_default_timezone_set_set()

See all articles