《PHP實例:php導入模塊文件分享》要點:
本文介紹了PHP實例:php導入模塊文件分享,希望對您有用。如果有疑問,可以聯系我們。
PHP教程代碼很簡單,大家注意看注釋就可以了.
代碼如下:
/**
?* 導入模塊文件
?*
?* @param string $classString 導入文件路徑字符串,可以用"."代替"/"
?* @param string $fileType 導入文件類型的擴展名(帶"."號),也可以是class/inc(簡寫方式)
?* @return Exception 如果導入成功則返回true,否則返回異常對象
?*
?* @example
?* importModule('gapi.Account') => include_once('modules/gapi/Account.class.php');
?*/
function importModule($classString, $fileType = 'class')
{
??? $filename = $module_path. strtr($classString, '.', '/');
??? switch ($fileType) {
??????? //導入類文件
??????? case 'class': $filename .= '.class.php'; break;
??????? //導入包括文件
??????? case 'inc': $filename .= '.inc.php'; break;
??????? //自定義導入文件的擴展名
??????? default: $filename .= $fileType; break;
??? }
??? if (is_file($filename))
??? {
??????? include_once($filename);
??? }
??? else
??? {
??????? exit('class "\\' . strtr($classString, '.', '\\') . '" is not found.');
??? }
}
PHP教程以上就是本文分享給大家的代碼了,希望大家能夠喜歡.
歡迎參與《PHP實例:php導入模塊文件分享》討論,分享您的想法,維易PHP學院為您提供專業教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/11693.html