Php import module file sharing _ PHP Tutorial

Source: Internet
Author: User
Php import module file sharing. Php import module file sharing this article shares with you the php import module file sharing. The main parameters include the import file path string, which can be used. extension of the imported file type (file sharing with the php import module ).

This article shares with you the php import module files. The main parameters include the import file path string, which can be used ". "In place of"/", the extension of the imported file type (". "), or class/inc (abbreviated). If the import is successful, true is returned. Otherwise, an exception object is returned. For more information, see.

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 the path string of the imported file. you can use "." instead "/"
* @ Param string $ fileType indicates the extension of the file type to be imported (with the "." number), or class/inc)
* @ Return Exception if the import is successful, true is returned; 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 ,'.','/');
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.

In this article, we will share with you the php import module file. The main parameters include the import file path string, which can be replaced by./and the extension of the import file type (...

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.