浏览模式: 标准 | 列表2008年06月的文章

include的另类用法

include()时,如果被包含文件使用了return返回值,那么include()就直接返回该return的值。

PHP代码
  1. <?php   
  2. //1.php   
  3. return 'hello world';   
  4. ?>  
PHP代码
  1. <?php   
  2. //2.php   
  3. $str = include '1.php';   
  4. echo "$str"//输出hello world   
  5. ?>   

利用这个特性可以方便地使用php文件来做配置。比如

PHP代码
  1. <?php   
  2. //config.php   
  3. return array(   
  4.             'db'=>array(   
  5.             'host' => 'localhost',   
  6.             'user' => 'root',   
  7.             'password' => 'root',   
  8.             'name' => 'test',   
  9.             'encoding' => 'utf8'  
  10.     )   
  11. );   

使用时只要 $config = include 'inc/config.php'; 避免了不必要的变量,节省内存.

另:

今天用editplus时,发现“函数列表”里空空的。原来是function前面有public等限定符。

把php的函数模板改动一下就认识了。

PHP代码
  1. ^[ \t]*(function|public|protected|private|static)[ \t].*\([^;]*$  

Tags: include, editplus

jQuery获取表单各元素的值及其AJAX应用

jQuery获取表单各元素的值及其AJAX应用.比较简单也是常用到的.

» 阅读全文

Tags: jquery

PATH_INFO方法实现页面伪静态的函数

先贴代码

PHP代码
  1. <?php      
  2. /*函数url_parse用于解析url,使用时需要在前面定义    
  3. *define('PATH_INFO',true);      
  4. *需要解析时调用该函数,取值方法用回$_GET['xxx']即可      
  5. */     
  6. function url_parse()      
  7. {      
  8.     if (!(isset($_SERVER['PATH_INFO']) && defined('PATH_INFO'))) {      
  9.         return;      
  10.     }      
  11.     $url = substr($_SERVER['PATH_INFO'], 1);      
  12.     $url = str_replace(array("'", '"', '.htm', '.html'), array('', '', '', ''), $url);    
  13.     $url = explode('/', $url);      
  14.     $param_count = count($url);      
  15.     for ($i = 0; $i < $param_count$i += 2) {      
  16.         if (isset($url[$i + 1]) && !is_numeric($url[$i])) {      
  17.             $_GET[$url[$i]] = $url[$i + 1];      
  18.         }      
  19.     }      
  20.     unset($param_count$url$i);      
  21. }      
  22. ?>  

 

说明:

www.yogool.cn/index.php/category/ajax 。(ajax后面可加.htm)这样,用$_GET['category']即可取出ajax.

再如 www.yogool.cn/index.php/category/ajax/page/2.htm,这样用$_GET['page']可取到2;它的页面相当于www.yogool.cn/index.php?category=ajax&page=2

淡水以前也写过,不过不是没写成函数,且要考虑到图片和css路径的问题.

原文:http://www.yogool.cn/index.php?controller=Default&action=ShowArticle&aid=10

Tags: path_info

30分钟搞定jQuery(E文)

内容: 

内容:

  1. jQuery特点
  2. CSS选择器用法
  3. jQuery集合
  4. jQuery集合操作
  5. 获取匹配元素的值
  6. DOM元素遍历
  7. 事件处理
  8. 安静加载运行
  9. 对象链串访问
  10. 疯狂链串(Crazy Chaining)
  11. Ajax用法
  12. 推荐了几个插件

 

Tags: jquery

PHP注释小技巧

留心处处出学问啊。这么简单的方法,为啥就没想到呢?

主动研究和被动学习的差别?

» 阅读全文

ThinkPHP框架问题备忘


1,用内置的prototype框架时,hide()和show()方法在ie下报错(object doesn't support this property or method),firefox3正常.

  改用$('suggestions').style.display = none/''后解决问题。


2,我不习惯用prototype框架,我习惯了jquery。但是我又不想浪费现成的自动验证功能。

  在<html:import type="js" file="Js.prototype" /> 等的最后边加上<html:import type="js" file="Js.Ajax.jquery" />。然后在页面的js块里,jQuery.noConflict();这样jquery就不在和prototype抢占$这个函数。jquery里用jQuery('#id')代替$('#id').

Tags: 框架