This article shares with you the php import module files. The main parameters include the import file path string, which can be used. instead, the extension (. or classinc.
This article shares with you the php import module files. The main parameters include the import file path string, which can be used. replace/, the extension of the imported file type (. can also be a class/inc (abbreviated ).
The code is very simple. You just need to pay attention to the comments.
The Code is as follows:
/**
* Import module files
*
* @ Param string $ classString import file path string, can be replaced with "." http://www.jb51.net /"
* @ Param string $ fileType indicates the extension of the file type to be imported (with the "." Number), or class/inc)
* @ Return Exception true is returned if the import is successful; otherwise, an Exception object is returned.
*
* @ Example
* ImportModule ('gapi. account') => include_once ('Les les/gapi/Account. class. php ');
*/
Function importModule ($ classString, $ fileType = 'class ')
{
$ Filename = $ module_path. strtr ($ classString, '.', 'HTTP: // www.jb51.net /');
Switch ($ fileType ){
// Import a class file
Case 'class': $ filename. = '. class. php'; break;
// Import the inclusion File
Case 'inc': $ filename. = '. inc. php'; break;
// Customize the extension of the imported File
Default: $ filename. = $ fileType; break;
}
If (is_file ($ filename ))
{
Include_once ($ filename );
}
Else
{
Exit ('class "\ '. strtr ($ classString,'. ',' \ ').'" is not found .');
}
}
The above is the code shared in this article. I hope you will like it.