我只用13行代碼開發的php框架,如果您對框架不理解,不知道框架究竟幫您做了什麽事,可以下載此框架看一下,
另外如果您想開發自己的框架也可以由這個框架的思路進行擴展.
源碼下載地址:http://download.csdn.net/detail/sibang/6197315
代碼:
<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> }.htaccess的內容
立即学习“PHP免费学习笔记(深入)”;

下邊是註釋:
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';
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号