Home >Backend Development >PHP Tutorial >PHP import module file sharing_PHP tutorial

PHP import module file sharing_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:02:55992browse

php import module file sharing

This article shares with you the php import module file sharing. The main parameter is the import file path string. You can use "." instead of "/" , the extension of the imported file type (with "." sign), or class/inc (abbreviation), returns true if the import is successful, otherwise returns an exception object, please refer to it if you need it.

The code is very simple, just pay attention to the comments.

The code is as follows:


/**
* Import module file
*
* @param string $classString Import file path string, you can use "." instead of "/"
* @param string $fileType The extension of the imported file type (with "." sign), or it can be class/inc (abbreviation)
* @return Exception Returns true if the import is successful, otherwise returns an exception object
*
* @example
* importModule('gapi.Account') => include_once('modules/gapi/Account.class.php');
*/
function importModule($classString, $fileType = 'class')
{
$filename = $module_path.strtr($classString, '.', '/');
switch ($fileType) {
//Import class file
case 'class': $filename .= '.class.php'; break;
//Import included files
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 with you in this article, I hope you like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/969347.htmlTechArticlephp import module file sharing This article will share with you the php import module file sharing. The main parameters are the import file path characters. String, you can use . instead of /, import the extension of the file type (with...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn