国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php類自動加載器實現(xiàn)方法

2024-05-04 23:38:09
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php類自動加載器實現(xiàn)方法,涉及php針對文件的讀取、判斷及字符串操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了php類自動加載器實現(xiàn)方法。分享給大家供大家參考。具體如下:

這里autoload 可兼容以下格式:

Cache_File_Json

class_xxx.php

xxx.class.php

xxx.php

php代碼如下:

 

 
  1. function __autoload($className){ 
  2. $dirs=explode('_',$className); 
  3. $fileName=array_pop($dirs); 
  4. //print_r($dirs); 
  5. $filePath=$fileName; 
  6. if(is_array($dirs) && (count($dirs) > 0)){ 
  7. //echo '/n---/n'; print_r($dirs); 
  8. $dirPath=''
  9. foreach ($dirs as $dir){ 
  10. if($dir){ 
  11. $dirPath.=strtolower($dir).DIRECTORY_SEPARATOR; 
  12. $filePath=$dirPath.$fileName.'.php'
  13. }else { 
  14. if( file_exists('class_'.$fileName.'.php')){ 
  15. $filePath='class_'.$fileName.'.php'
  16. }else { 
  17. if( file_exists($fileName.'.class.php')){ 
  18. $filePath=$fileName.'.class.php'
  19. else { 
  20. $filePath=$fileName.'.php'
  21. }  
  22. //var_dump($filePath); 
  23. require $filePath; 

希望本文所述對大家的php程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 景洪市| 西和县| 芦山县| 兴宁市| 特克斯县| 淮阳县| 达拉特旗| 曲水县| 长白| 新营市| 阜南县| 黔西县| 应城市| 明光市| 屏边| 泗洪县| 朝阳县| 沂水县| 南华县| 双鸭山市| 石柱| 彭山县| 佛冈县| 彭州市| 汉寿县| 法库县| 达孜县| 壤塘县| 革吉县| 尉犁县| 平阳县| 大悟县| 兴国县| 武平县| 亳州市| 呼图壁县| 潜山县| 枣阳市| 昌江| 越西县| 资阳市|