Home  >  Article  >  php教程  >  The PHP framework I developed using 13 lines of code

The PHP framework I developed using 13 lines of code

WBOY
WBOYOriginal
2016-07-09 09:10:131514browse

The PHP framework I developed with only 13 lines of code. If you don’t understand the framework and don’t know what the framework does for you, you can download this framework and take a look,

In addition, if you want to develop your own framework, you can also extend the ideas of this framework.

Source code download address: http://download.csdn.net/detail/sibang/6197315

Code:

<span style="color: #008080;"> 1</span> <span style="color: #000000;">PHP
</span><span style="color: #008080;"> 2</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*
</span><span style="color: #008080;"> 3</span> <span style="color: #008000;">    PHP極簡框架
</span><span style="color: #008080;"> 4</span> <span style="color: #008000;">    交流:
</span><span style="color: #008080;"> 5</span> <span style="color: #008000;">        QQ群: 223494678
</span><span style="color: #008080;"> 6</span> <span style="color: #008000;">        http://7di.net
</span><span style="color: #008080;"> 7</span> <span style="color: #008000;">    用法
</span><span style="color: #008080;"> 8</span> <span style="color: #008000;">        http://URL
</span><span style="color: #008080;"> 9</span> <span style="color: #008000;">        http://URL/hello
</span><span style="color: #008080;">10</span> <span style="color: #008000;">        http://URL/seven.php?w=hello
</span><span style="color: #008080;">11</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*/</span>
<span style="color: #008080;">12</span> 
<span style="color: #008080;">13</span> <span style="color: #008080;">Header</span>('Content-type: text/html; charset=UTF-8'<span style="color: #000000;">);
</span><span style="color: #008080;">14</span> <span style="color: #800080;">$w</span>=<span style="color: #0000ff;">isSet</span>(<span style="color: #800080;">$_REQUEST</span>['w']) ? <span style="color: #008080;">AddsLashes</span>(<span style="color: #800080;">$_REQUEST</span>['w']) : ''<span style="color: #000000;">;
</span><span style="color: #008080;">15</span> <span style="color: #800080;">$w</span>=(<span style="color: #008080;">Trim</span>(<span style="color: #800080;">$w</span>)=='') ? 'index' : <span style="color: #800080;">$w</span><span style="color: #000000;">;
</span><span style="color: #008080;">16</span> 
<span style="color: #008080;">17</span> <span style="color: #0000ff;">IF</span>(!<span style="color: #008080;">is_callable</span>(<span style="color: #800080;">$w</span><span style="color: #000000;">)) {
</span><span style="color: #008080;">18</span>     <span style="color: #0000ff;">Exit</span>('Error:'.<span style="color: #ff00ff;">__LINE__</span>.',參數錯誤!'<span style="color: #000000;">);
</span><span style="color: #008080;">19</span> <span style="color: #000000;">}
</span><span style="color: #008080;">20</span> <span style="color: #800080;">$w</span><span style="color: #000000;">();
</span><span style="color: #008080;">21</span> 
<span style="color: #008080;">22</span> <span style="color: #0000ff;">Function</span><span style="color: #000000;"> hello(){
</span><span style="color: #008080;">23</span>     <span style="color: #0000ff;">Echo</span> 'Hello World!'<span style="color: #000000;">;
</span><span style="color: #008080;">24</span> <span style="color: #000000;">}
</span><span style="color: #008080;">25</span> 
<span style="color: #008080;">26</span> <span style="color: #0000ff;">Function</span><span style="color: #000000;"> index(){
</span><span style="color: #008080;">27</span>     <span style="color: #0000ff;">Echo</span> '此框架由Seven編寫,來自QQ群:223494678'<span style="color: #000000;">;
</span><span style="color: #008080;">28</span> }

Contents of .htaccess

Below is the comment:

Header('Content-type: text/html; charset=UTF-8');
//定義編碼

$w=isSet($_REQUEST['w']) ? AddsLashes($_REQUEST['w']) : '';
//獲取參數w的值,w來自于rewrite規則文件.htaccess

$w=(Trim($w)=='') ? 'index' : $w;
//如果參數w的值為空,則訪問默認的index方法

IF(!is_callable($w)) {
	//如果$w所屬的function不存在

	Exit('Error:'.__LINE__.',參數錯誤!');
	//拋出錯誤
}
$w();
//調用$w名稱對應的function,例如:http://URL/hello會調用hello()這個function

//自定義方法(可自由擴展)
Function hello(){
	Echo 'Hello World!';
}

Function index(){
	Echo '此框架由Seven編寫,來自QQ群:223494678';
}

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