Php import module File Sharing

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.