I'm twiting

访问统计

free counters

PHP遍历对象

自PHP 5 起,还可能遍历对象。
注: 当 foreach 开始执行时,数组内部的指针会自动指向第一个单元。这意味着不需要在 foreach 循环之前调用 reset()。
注: 除非数组是被引用,foreach 所操作的是指定数组的一个拷贝,而不是该数组本身。因此数组指针不会被 each() 结构改变,对返回的数组单元的修改也不会影响原数组。不过原数组的内部指针的确在处理数组的过程中向前移动了。假定 foreach 循环运行到结束,原数组的内部指针将指向数组的结尾。
Share on Facebook

Share on Facebook

session_start的问题

之前做的表单ajax功能今天突然无法运转。
查到最后发现ajax请求的时候没有自动打开session了,才发现是session autostart被关掉了。在session请求前加session_start();就好了。
另外使用cakephp的童鞋把session.level改为low也可以解决这个问题。
这个bug我花了四个小时才分析出来的。web做到最后真是细微之处见真功。
Share on Facebook

Share on Facebook

PHP Interview questions from YAHOO

1. Which of the following will not add john to the users array? B
A. $users[] = ‘john’;
B. array_add($users,’john’);
C. array_push($users,‘john’);
D. $users ||= ‘john’;
2. What’s the difference between sort(), assort() and ksort? Under what circumstances would you use each of these?

sort()
asort()
ksort()

排序对象
元素的值
元素的值
元素键值

排序方式
字母顺序
字母顺序
字母顺序

重置索引
重置
不重置
不重置

3. What would the following code print to the browser? Why?
$num = 10;
function multiply(){
$num = $num * [...]

Share on Facebook

Zabbix的一个bug

最近公司的项目要分解zabbix。分析它的代码的时候发现其数据库类有一个bug:使用mysql_pconnect建立一个数据库连接,却用mysql_close去关闭!这样做是关不掉的!因为mysql_pconnect建立的是一个持久化的连接,使用完毕会被放回连接池的,即使脚本执行完毕,这个连接也不会关闭。
一下是php.net对mysql_close的解释:
mysql_close() closes the non-persistent connection to the MySQL server that’s associated with the specified link identifier. If link_identifier isn’t specified, the last opened link is used.
一下是有问题的代码片段:
$mysql_server = $DB['SERVER'].( !empty($DB['PORT']) ? ‘:’.$DB['PORT'] : ”);
if (!$DB['DB']= mysql_pconnect($mysql_server,$DB['USER'],$DB['PASSWORD'])){
$error = ‘Error connecting to database ['.mysql_error().']‘;
$result = [...]

Share on Facebook

编译PHP5缺t1lib包解决方案

遇到这个报错:
configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.
以下是解决步骤:
1. 下载t1lib-5.1.2.tar.gz
2. 解决依赖关系:apt-get build-dep t1lib
3. 安装:./configure & make without_doc & make install
4. 编译php5 时在./configure后加上 –with-t1lib=/usr/local/share/t1lib。再次编译就能通过了。
Share on Facebook

Share on Facebook

在 Ubuntu 上使用 apt-get 安装配置 Apache2.2 + PHP5.2 + MySQL5.0

安装以下这些包
apache2 php5-mysql libapache2-mod-php5 mysql-server libapache2-mod-auth-mysql php5-cli
(中间会提示输入MySQL密码)
参考:LAMP服务器的配置
Share on Facebook

Share on Facebook

Constructor 主题缺少title的bug

一直觉得这款主题很切合我的性格,可是发现它的title不能正常输出博客标题。稍微研究了一下,其实只要编辑
wp-content/themes/constructor/header.php
这个文件,将
<?php wp_title(”); ?>
这一行替换为
<?php bloginfo(’name’); ?> <?php if ( is_single() ) { ?> » Blog Archive <?php } ?> <?php wp_title(); ?>
Share on Facebook

Share on Facebook

调试技巧

# tail -f /var/log/apache2/error.log
运行 apache2 错误日志
tail -n 1000 /var/log/apache2/error.log
apache2错误日志的位置,显示 1000 行
/var/log/syslog
系统错误日志的位置
Share on Facebook

Share on Facebook