首頁 後端開發 php教程 PHP資料夾遍歷,圖片等比例壓縮

PHP資料夾遍歷,圖片等比例壓縮

Jul 25, 2016 am 08:42 AM

等比例, PHP
  1. /**
  2. * 來源:網際網路
  3. */
  4. class image
  5. {
  6. var $w_pct = 100; //> var $w_quality = 100; //品質
  7. var $w_minwidth = 500; //最小寬
  8. var $w_minheight = 500; //最小高
  9. var $interlace = 0; //影像是否為隔行掃描的
  10. var $fontfile ; //字型檔
  11. var $w_img ; //預設浮水印圖
  12. function __construct()
  13. {
  14. $this->fontfile = $_SERVERVER ['DOCUMENT_ROOT'].'/public/fonts/simhei.ttf';
  15. $this->w_img = '';
  16. }
  17. function image()
  18. {
  19. $this- >__construct();
  20. }
  21. function info($img)
  22. {
  23. $imageinfo = getimagesize($img); //傳回影像資訊陣列0=>寬的像素1 =>高的像素2=>是圖像類型的標記3 =>是文字字串,內容為“height="yyy" width="xxx"”,
  24. if($imageinfo === false) return false ;
  25. $imagetype = strtolower(substr(image_type_to_extension($imageinfo[2]),1)); //取得映像檔類型$imageinfo[2]是映像類型的標記
  26. $imagesize = filesize($img ); //圖片大小
  27. $info = array(
  28. 'width'=>$imageinfo[0],
  29. 'height'=>$imageinfo[1],
  30. 'type'=> $imagetype,
  31. 'size'=>$imagesize,
  32. 'mime'=>$imageinfo['mime']
  33. );
  34. return $info;
  35. }
  36. /**
  37. * 追蹤
  38. *
  39. * @param string $image
  40. * @param string $filename
  41. * @param int $maxwidth
  42. * @param int $maxheight
  43. * param string $suffix
  44. * @param int $autocut
  45. * @return string
  46. */
  47. function thumb($image, $filename = '',$maxwidth = 50, $maxheight = 50, $suffix='_thumb', $autocut = 0)
  48. {
  49. if( !$this->check($image)) return false;
  50. $info = $this->info($image); //取得圖片資訊
  51. if($info === false) return false;
  52. $srcwidth = $info['width']; //源圖寬
  53. $srcheight = $info['height']; //源圖高
  54. $pathinfo = pathinfo ($image);
  55. $type = $pathinfo['extension']; //取得副檔名
  56. if(!$type) $type = $info['type']; //若沒有取到,用$info['type']
  57. $type = strtolower($type);
  58. unset($info);
  59. $scale = min($maxwidth/$srcwidth, $maxheight/$srcheight) ; //取得縮略比例
  60. //取得依照來源圖的比列
  61. $createwidth = $width = (int) ($srcwidth*$scale);//取得縮寬();
  62. $createheight = $height = (int)($srcheight*$scale);//(); //取得縮略高
  63. $psrc_x = $psrc_y = 0;
  64. if($autocut) //依照縮圖的比例來取得
  65. {
  66. if($maxwidth/$maxheight=$height) //如果縮圖按比列比來源圖窄的話
  67. {
  68. $width = $maxheight/$height*$width; //寬依對應比例做處理
  69. $height = $maxheight;// //高不變
  70. }
  71. elseif( $maxwidth/$maxheight>$srcwidth/$srcheight && $maxwidth>=$width)//如果縮圖按比列比源圖寬的話
  72. {
  73. $height = $maxwidth/$width*$height ;//
  74. $width = $maxwidth;
  75. }
  76. if($maxwidth == '55'){
  77. $width = '55';
  78. $createwidth = '55';
  79. }
  80. if($maxwidth == '110'){
  81. $width = '110';
  82. $createwidth = '110';
  83. }
  84. }
  85. }
  86. if($srcwidth $createwidth= $srcwidth;
  87. $createheight = $srcheight;
  88. }
  89. $createheight = $srcheight;
  90. }
  91. }
  92. $create imagecreatefrom'.($type=='jpg' ? 'jpeg' : $type); //找到不同的圖片處理函數
  93. $srcimg = $createfun($image); //回傳圖片識別碼 if($type != 'gif' && function_exists('imagecreatetruecolor')){ $thumbimg = imagecreatetruecolor($createwidth, $createheight); //新建一個真彩色圖像 }else{
  94. if($maxwidth == '110' && $srcheight >= $srcwidth){
  95. $height1 = 72;
  96. $thumbimg = imagecreate($width, $height1); //調色盤為基礎的圖片
  97. }elseif ($maxwidth == '110' && $srcheight $width1 = 110;
  98. $thumbimg = imagecreate($width1, $height) ; //新建一個基於調色盤的圖片
  99. }else{
  100. $thumbimg = imagecreate($width, $height); //新建一個基於調色盤的圖片
  101. }
  102. }
  103. if(function_exists('imagecopyresampled')){ //重採樣拷貝部分影像並調整大小,真彩
  104. //imagecopyresampled(新圖,來源圖,新圖左上角x距離,新圖左上角y距離,源圖左上角x距離,源圖左上角y距離,新圖寬,新圖高,源圖寬,源圖高)
  105. if($maxwidth == '110' && $srcheight >= $srcwidth){
  106. $psrc_x = 0;
  107. $psrc_yz = $height/2;
  108. $psrc_y = $psrc_yz;
  109. $width = '110';
  110. }
  111. }
  112. if ($maxwidth == '110' && $srcheight >= $srcwidth && $srcheight>= '72' && $srcwidth $psrc_x = 0;
  113. $psrc_yz = $height/yz = $height/ 2;
  114. $psrc_y = $psrc_yz;
  115. $width = '110';
  116. }
  117. if($maxheight == '72' && $srcheight = '110'){
  118. $cha = ($maxheight-$srcheight)/2;
  119. $psrc_y = -($cha);
  120. $width = $srcwidth;
  121. $height = '72';
  122. $srcheight = '72';
  123. }
  124. imagecopyresampled($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $width, $height, $. $srcwidth, $srcheight);
  125. }else{ //拷貝部分圖像並調整大小,調色板
  126. imagecopyresized($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $ width, $height, $srcwidth, $srcheight);
  127. }
  128. if($type=='gif' || $type=='png')
  129. {
  130. //imagecolorallocate 為一幅圖片分配顏色
  131. $background_color = imagecolorallocate($thumbimg, 0, 255, 0); // 為基於調色盤的圖片填滿背景色, 指派一個綠色
  132. // imagecolortransparent 將某個顏色定義為透明色
  133. imagecolortransparent($thumbimg, $background_color); // 設定為透明色,若註解掉該行則輸出綠色的圖
  134. }
  135. // imageinterlace 啟動或禁止隔行掃描
  136. if ($type=='jpg' || $type=='jpeg') imageinterlace($thumbimg, $this->interlace);
  137. $imagefun = 'image'.($type=='jpg' ? ' jpeg' : $type);
  138. //imagejpeg imagegif imagepng
  139. if(empty($filename)) $filename = substr($image, 0, strrpos($image, '.')).$suffix. '.'.$type; //取得檔案名稱
  140. //aaa.gif aaa_thumb.gif
  141. $imagefun($thumbimg, $filename); //新圖片
  142. imagedestroy($thumbimg); / /銷毀縮圖
  143. imagedestroy($srcimg); //銷毀來源圖
  144. return $filename;
  145. }
  146. /**
  147. * 限制寬或高
  148. *
  149. * @param string $image
  150. * @param int $maxwidth
  151. * @param int $maxheight
  152. * @param string $suffix> * @param int $maxheight
  153. * @param string $suffix > * @return string
  154. */
  155. function thumb3($image,$ maxwidth = 0, $maxheight = 0, $suffix='_thumb')
  156. {
  157. if( !$this->check($image)) return false;
  158. $info = $this->info ($image); //取得圖片資訊
  159. if($info === false) return false;
  160. $srcwidth = $info['width']; //來源圖寬
  161. $srcheight = $info['height']; //來源圖高
  162. $pathinfo = pathinfo($image);
  163. $type = $pathinfo['extension']; //取得副檔名
  164. if(! $type) $type = $info['type']; //如果沒有取到,用$info['type']
  165. $type = strtolower($type);
  166. unset($info);
  167. if($maxwidth==0){
  168. $scale = $maxheight/$srcheight;
  169. if($scale $createwidth = $srcwidth*$scale;
  170. $createheight = $maxheight;
  171. }else{
  172. $createwidth = $srcwidth;
  173. $createheight = $srcheight; }
  174. }
  175. if($maxheight==0){
  176. $scale = $maxwidth/$srcwidth;
  177. if($scale $createwidth = $maxwidth;
  178. $createheight = $srcheight*$scale;
  179. }else{
  180. $createwidth = $srcwidth;
  181. $createheight = $srcheight;
  182. }
  183. }
  184. $ps = 0;
  185. $createfun = 'imagecreatefrom'.($type=='jpg' ? 'jpeg' : $type); //找到不同的映像處理函數
  186. $srcimg = $createfun($image) ; //回傳圖片識別碼
  187. if($type != 'gif' && function_exists('imagecreatetruecolor')){
  188. $thumbimg = imagecreatetruecolor($createwidth, $createheight); //新建一個真彩色圖像
  189. }else{
  190. $thumbimg = imagecreate($createwidth, $createheight); //新建一個基於調色盤的圖片
  191. }
  192. if(function_exists('imagecopyresampled')){ //重採樣拷貝部分影像並調整大小,真彩
  193. //imagecopyresampled(新圖,源圖,新圖左上角x距離,新圖左上角y距離,源圖左上角x距離,源圖左上角y距離,新圖寬,新圖高,源圖寬,源圖高)
  194. imagecopyresampled($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $createwidth, $createheight, $srcwidth, $srcheightidth, $srcheight );
  195. }else{ //拷貝部分圖像並調整大小,調色板
  196. imagecopyresized($thumbimg, $srcimg, 0, 0, $psrc_x, $psrc_y, $createwidth, $createheight, $createheight, $srcwidth, $srcheight);
  197. }
  198. if($type=='gif' || $type=='png')
  199. {
  200. //imagecolorallocate 為一幅圖像分配顏色
  201. $background_color = imagecolorallocate($thumbimg, 0, 255, 0); // 為基於調色盤的圖片填滿背景色, 指派一個綠色
  202. // imagecolortransparent 將某個顏色定義為透明色
  203. imagecolortransparent($thumbimg, $background_color); // 設定為透明色,若註解掉該行則輸出綠色的圖
  204. }
  205. // imageinterlace 啟動或禁止隔行掃描
  206. if($type== 'jpg' || $type=='jpeg') imageinterlace($thumbimg, $this->interlace);
  207. $imagefun = 'image'.($type=='jpg' ? 'jpeg' : $type );
  208. //imagejpeg imagegif imagepng
  209. $filename = substr($image, 0, strrpos($image, '.')).$suffix.'.'.$type; //取得檔案名稱
  210. //aaa.gif aaa_thumb.gif
  211. $imagefun($thumbimg, $filename); //新圖片
  212. imagedestroy($thumbimg); //銷毀縮圖
  213. imagedestroy($thumbimg); //銷毀縮圖
  214. imagedestroy($srcimg); //銷毀來源圖
  215. return $filename;
  216. }
  217. /**
  218. * 產生特定尺寸縮圖解決原版縮圖無法滿足特定尺寸的問題PS:會裁掉圖片不符合縮圖比例的部分
  219. * @static
  220. * @access public
  221. * @ ?
  222. * @param boolean $interlace 啟用隔行掃描
  223. * @return void
  224. */
  225. static function thumb2($image, $thumbname, $type='', $maxWidth=200 , $maxHeight=50, $interlace=true) {
  226. // 取得原圖資訊
  227. $info = Image::getImageInfo($image);
  228. if ($info !== false) {
  229. $srcWidth = $info['width'];
  230. $srcHeight = $info['height'];
  231. $type = empty($type) ? $info['type'] : $type;
  232. $type = strtolower($type);
  233. $interlace = $interlace ? 1 : 0;
  234. unset($info);
  235. $scale = max($maxWidth / $srcWidth, $maxHeight / $srcHeight); // 計算縮放比例
  236. //判斷原圖和縮圖比例如原圖寬於縮圖則裁掉兩邊反之..
  237. if($maxWidth / $srcWidth > $maxHeight / $srcHeight){
  238. //高於
  239. $srcX = 0;
  240. $srcY = ($srcHeight - $maxHeight / $scale) / 2 ;
  241. $cutWidth = $srcWidth;
  242. ;
  243. $cutHeight = $maxHeight / $scale;
  244. }else{
  245. //寬於
  246. $srcX = ($srcWidth - $maxWidth / $scale) / 2;
  247. $srcY = 0;
  248. $cutWidth = $maxWidth / $scale;
  249. $cutHeight = $srcHeight;
  250. }
  251. // 載入原圖
  252. $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
  253. $srcImg = $createFun($image) ;
  254. //建立錢包
  255. if ($type != 'gif' && function_exists('imagecreatetruecolor'))
  256. $thumbImg = imagecreatetruecolor($maxWidth, $maxHeight);
  257. $thumbImg = imagecreate($maxWidth, $maxHeight);
  258. // 複製圖片
  259. if (function_exists("ImageCopyResampled"))

    imagecoresppmg,mhmg(pybmg,$pmg,$p,m, 0, $srcX, $srcY, $maxWidth, $maxHeight, $切割寬度,$切割高度);

  260. else
  261. imagecopyresized($thumbImg, $srcImg, 0, 0, $srcX, $srcY, $maxsrcth , $maxHeight, $cutWidth, $cutHeight);
  262. if ('gif' == $type || 'png' == $type) {
  263. //imagealphablending($thumbImg, false);//取消預設的混色模式
  264. //imagesavealpha( $thumbImg,true);//設定保存完整的alpha 通道資訊
  265. $background_color = imagecolorallocate($thumbImg, 0, 255, 0); // 指派一個綠色
  266. imagecolortransparent($thumbImg, $background_color); // 設定為透明色,若註解掉該行則輸出綠色的圖
  267. }
  268. // 對jpeg圖形設定隔行掃描
  269. if ('jpg' == $type || ' jpeg' == $type)
  270. imageinterlace($thumbImg, $interlace);
  271. // 產生圖片
  272. $imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
  273. @chmod(dirname($thumbname),0777);
  274. $imageFun($thumbImg, $thumbname);
  275. imageFun($thumbImg, $thumbname);
  276. imagedestroy( $thumbImg);
  277. imagedestroy($srcImg);
  278. 回傳$thumbname;
  279. }
  280. 回傳false;
  281. }
  282. /**
  283. /**
  284. /** /
  285. static function getImageInfo($img) {
  286. $imageInfo = getimagesize($img);
  287. if ($imageInfo !== false) {
  288. $imageType = strtolower(subsstr image_type_to_extension($imageInfo[2]), 1));
  289. $imageSize = 檔案大小($img);
  290. $info = array(
  291. "寬度" => $imageInfo[0],
  292. "高度" => $imageInfo[1],
  293. "型" => $imageType,
  294. "大小" => $imageSize,
  295. "mime" => $imageInfo['mime']
  296. );
  297. 回傳$info;
  298. } else {
  299. 回傳false;
  300. }
  301. }
  302. //watermark(來源圖,產生檔案,產生位置,水印檔,水印文字,背景色)
  303. function watermark($source, $target = '' , $w_pos = 9, $w_img = '', $w_text = '', $w_font = 12, $w_color = ' #cccccc',$x='',$y='')
  304. {
  305. if(!$this->check($source)) 回傳false;
  306. if(!$target) $target = $source;
  307. if ($w_img == '' && $w_text == '')
  308. $w_img = $this->w_img;
  309. $source_info = getimagesize($source);
  310. $source_w = $source_info[0]; //取得寬
  311. $source_h = $source_info[1]; //取得高
  312. if($source_w w_minwidth || $source_h w_minheight) return false; // 寬與達不到要求直接回傳
  313. switch($source_info[2]) // 新圖
  314. {
  315. case 1 :
  316. $source_img = imagecreatefromgif($ source);
  317. 休息;
  318. 案例2 :
  319. $source_img = imagecreatefromjpeg($source);
  320. 休息;
  321. 案例3 :
  322. $source_img = imagecreatefrompng($source);
  323. 休息;
  324. 預設:
  325. 回傳false;
  326. }
  327. if(!empty($w_img) && file_exists($w_img)) //水印檔案
  328. {
  329. $ifwaterimage = 1; // 是否浮水印圖
  330. $water_info = getimaimaize($w_imgesg) ; //浮水印資訊
  331. $width = $water_info[0];
  332. $height = $water_info[1];
  333. switch($water_info[2])
  334. {
  335. 情況1 :
  336. $water_img = imagecreatefromgif($w_img);
  337. 休息;
  338. 案例2 :
  339. $water_img = imagecreatefromjpeg($ 3 :
  340. $water_img = imagecreatefrompng($w_img);
  341. 休息;
  342. 預設:
  343. 回傳;
  344. }
  345. }
  346. else $ifwaterimage = 0;
  347. //imagettfbbox本函數計算並傳回一個包圍TrueType文字範圍的虛擬方框的像素大小。
  348. //imagettfbbox ( 字體大小, 字體角度, 字體檔案,檔案)
  349. // echo $this->fontfile;
  350. $temp = imagettfbbox(ceil($w_font*1.6), 0, $this ->fontfile, $w_text);//取得使用truetype 字體的文字的範圍
  351. $width = $temp[4] - $temp[6]; //右上角X 位置- 左上角X 位置
  352. $height = $temp[3] - $temp[5]; //右下角Y 位置- 右上角Y 位置
  353. unset($temp);
  354. }
  355. switch($w_pos)
  356. {
  357. case 0: //隨機位置
  358. $wx = rand(0,($source_w - $width));
  359. $wy = rand(0,($source_h - $height));
  360. break;
  361. case 1: //左上角
  362. $wx = 25;
  363. $wy = 25;
  364. break;
  365. case 2: //上面中間位置
  366. $ wx = ($source_w - $width) / 2;
  367. $wy = 0;
  368. break;
  369. case 3: //右上角
  370. $wx = $source_w - $width;
  371. $wy = 0;
  372. break;
  373. case 4: //左邊中間位置
  374. $wx = 0;
  375. $wy = ($source_h - $height) / 2;
  376. break;
  377. case 5: //中間位置
  378. $wx = ($source_w - $width) / 2;
  379. $wy = ($source_h - $height) / 2;
  380. break;
  381. case 6: //底部中間位置
  382. $wx = ($source_w - $width) / 2;
  383. $wy = $source_h - $height;
  384. break;
  385. case 7: //左下角
  386. $wx = 0;
  387. $wy = $source_h - $height;
  388. break;
  389. case 8: //右邊中間位置
  390. $wx = $source_w - $width;
  391. $wy = ($source_h - $height) /2;
  392. break;
  393. case 9: //右下角
  394. $wx = $source_w - $width;
  395. $wy = $source_h - $height ;
  396. break;
  397. default: //隨機
  398. $wx = rand(0,($source_w - $width));
  399. $wy = rand(0,($source_h - $height));
  400. break;
  401. case 10://自訂位置
  402. $wx = $x;
  403. $wy = $y;
  404. case 11: //底部中間位置--手工客專用
  405. $wx = ($source_w - $width) / 2;
  406. $wy = $source_h - $height-50;
  407. break;
  408. break;
  409. }
  410. if($ifwaterimage) //如果有浮水印圖
  411. {
  412. //imagecopymerge 拷貝並合併影像的一部份
  413. //參數(源圖,水印圖,拷貝到源圖x位置,拷貝到來源圖y位置,從水印圖x位置,從水印圖y位置,高,寬,透明度)
  414. //imagecopymerge($source_img, $water_img, $wx, $wy, 0, 0, $width, $height, $this->w_pct);
  415. imagecopy($source_img,$water_img,$wx,$wy,0,0,$width,$height);
  416. }
  417. else
  418. {
  419. if(!empty($w_color) && (strlen($w_color)==7))
  420. {
  421. $r = hexdec(substr($w_color,1,2) ); //取得紅色
  422. $g = hexdec(substr($w_color,3,2)); //取得綠色
  423. $b = hexdec(substr($w_color,5)); //取得藍色
  424. }
  425. else
  426. {
  427. return;
  428. }
  429. //imagecolorallocate 基於調色盤的圖片填滿背景色
  430. //imagestring 水平畫一行字串
  431. //imagestring(來源圖,字體大小,位置X,位置Y,文字,顏色)
  432. //參數($image, float $size, float $angle, int $x, int $y, int $ color, string $fontfile, string $text)
  433. imagettftext($source_img,$w_font,0,$wx,$wy,imagecolorallocate($source_img,$r,$g,$b),$this->fontfile, $w_text);
  434. //imagestring($source_img,$w_font,$wx,$wy,$w_text,imagecolorallocate($source_img,$r,$g,$b));
  435. }
  436. //輸出到檔案或瀏覽器
  437. switch($source_info[2])
  438. {
  439. case 1 :
  440. imagegif($source_img, $target); //以GIF 格式將影像輸出至瀏覽器或檔案
  441. break;
  442. case 2 :
  443. imagejpeg($source_img, $target, $this->w_quality); //以JPEG 格式將影像輸出到瀏覽器或檔案
  444. break;
  445. case 3 :
  446. imagepng($source_img, $target); //以PNG 格式將圖片輸出到瀏覽器或檔案
  447. break;
  448. default :
  449. return;
  450. }
  451. if(isset($water_info))
  452. {
  453. unset($water_info); //銷毀
  454. }
  455. if(isset($water_img))
  456. {
  457. imagedestroy($water_img); //銷毀
  458. }
  459. unset($source_info);
  460. imagedestroy($source_img);
  461. return true; //gd庫必須存在,後綴為jpg|jpeg|gif|png,文件存在,imagecreatefromjpeg或者imagecreatefromgif存在
  462. function check($image)
  463. {
  464. return extension_loaded('gd') &&
  465. preg_match("/.(JPG|JPEG|PNG|GIF|jpg|jpeg|gif|png)/i", $image, $m) &&
  466. file_exists($image) &&
  467. function_exists('imagecreatefrom '.($m[1] == 'jpg' ? 'jpeg' : $m[1]));
  468. //imagecreatefromjpeg
  469. //imagecreatefromgif
  470. //imagecreatefrompng
  471. }
  472. }
  473. /**
  474. 縮圖
  475. 1.新建一個圖像資源通過imagecreatefromgif imagecreatefromjpeg imagecreatefrompng
  476. 2.imagecopyresampled 拷貝圖片,並調整大小
  477. 水印:圖片
  478. 2.加浮水印
  479. 圖片浮水印:imagecopymerge 把2張圖合併在一起
  480. 文字浮水印:imagettftext 寫入文字
  481. */
  482. error_reporting(0);
  483. $hostdir = dirname(__FILE__);
  484. $filesnames = scandir($hostdir.'/desktop' );
  485. $img = new image();
  486. foreach($filesnames as $name){
  487. if($name != '.' && $name != '..'){
  488. $imgPath = $hostdir.'/desktop/';
  489. $imgsize = getimagesize($imgPath.$name);
  490. $imgInfo = explode('.',$name);
  491. $imginfo2 = explode('_',$imgInfo[0]);
  492. if($imginfo2[count($imginfo2)-1] != 'small'){
  493. $img_small = $imgPath.$imgInfo[0] .'_small.'.$imgInfo[1];
  494. $img->thumb2($imgPath.$name,$img_small,'',$imgsize[0]/4,$imgsize[1]/4);
  495. }
  496. }
  497. }
  498. 複製程式碼

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

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

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

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

熱門話題

Java教學
1665
14
CakePHP 教程
1423
52
Laravel 教程
1321
25
PHP教程
1269
29
C# 教程
1249
24
PHP和Python:比較兩種流行的編程語言 PHP和Python:比較兩種流行的編程語言 Apr 14, 2025 am 12:13 AM

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

說明PHP中的安全密碼散列(例如,password_hash,password_verify)。為什麼不使用MD5或SHA1? 說明PHP中的安全密碼散列(例如,password_hash,password_verify)。為什麼不使用MD5或SHA1? Apr 17, 2025 am 12:06 AM

在PHP中,應使用password_hash和password_verify函數實現安全的密碼哈希處理,不應使用MD5或SHA1。1)password_hash生成包含鹽值的哈希,增強安全性。 2)password_verify驗證密碼,通過比較哈希值確保安全。 3)MD5和SHA1易受攻擊且缺乏鹽值,不適合現代密碼安全。

PHP行動:現實世界中的示例和應用程序 PHP行動:現實世界中的示例和應用程序 Apr 14, 2025 am 12:19 AM

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。

PHP:網絡開發的關鍵語言 PHP:網絡開發的關鍵語言 Apr 13, 2025 am 12:08 AM

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

PHP的持久相關性:它還活著嗎? PHP的持久相關性:它還活著嗎? Apr 14, 2025 am 12:12 AM

PHP仍然具有活力,其在現代編程領域中依然佔據重要地位。 1)PHP的簡單易學和強大社區支持使其在Web開發中廣泛應用;2)其靈活性和穩定性使其在處理Web表單、數據庫操作和文件處理等方面表現出色;3)PHP不斷進化和優化,適用於初學者和經驗豐富的開發者。

PHP類型提示如何起作用,包括標量類型,返回類型,聯合類型和無效類型? PHP類型提示如何起作用,包括標量類型,返回類型,聯合類型和無效類型? Apr 17, 2025 am 12:25 AM

PHP類型提示提升代碼質量和可讀性。 1)標量類型提示:自PHP7.0起,允許在函數參數中指定基本數據類型,如int、float等。 2)返回類型提示:確保函數返回值類型的一致性。 3)聯合類型提示:自PHP8.0起,允許在函數參數或返回值中指定多個類型。 4)可空類型提示:允許包含null值,處理可能返回空值的函數。

PHP和Python:代碼示例和比較 PHP和Python:代碼示例和比較 Apr 15, 2025 am 12:07 AM

PHP和Python各有優劣,選擇取決於項目需求和個人偏好。 1.PHP適合快速開發和維護大型Web應用。 2.Python在數據科學和機器學習領域佔據主導地位。

PHP與其他語言:比較 PHP與其他語言:比較 Apr 13, 2025 am 12:19 AM

PHP適合web開發,特別是在快速開發和處理動態內容方面表現出色,但不擅長數據科學和企業級應用。與Python相比,PHP在web開發中更具優勢,但在數據科學領域不如Python;與Java相比,PHP在企業級應用中表現較差,但在web開發中更靈活;與JavaScript相比,PHP在後端開發中更簡潔,但在前端開發中不如JavaScript。

See all articles