Category Archives: PHP Rocks

PHP, XML and encoding

Not until I tried to parse an RSS feed encoded in GB2312 did I realize how painful it is to deal with encoding in PHP. It began with the xml_parser_create function, which is as awkward as it is clever at … Continue reading

Posted in PHP Rocks | Leave a comment

PHP MySQL字符集的问题

Key words: PHP, MySQL, Character set, 乱码 我的配置: Apache2.2.2 + PHP 5.1.4 + MySQL 5.0.21 + Windows Server 2003 MySQL Server上有关character set的设置都设为utf8,但总是有乱码现象。而且phpMyAdmin, EMS SQL Manager和自己的php程序的乱码还互不相同,后来用在自己的php程序中查询show variables,发现character_set_client, character_set_connection, character_set_results都是latin1。其他工具的相关设置也没有设正确。 经验:一定要确认character set在client和server端一致,还要确认各个数据库管理工具(e.g. phpMyAdmin, EMS SQL Manager)的设置都正确。   MySQL 4.1开始支持character set和collation,安装的时候(Windows installer)人们往往没有留意这些设置,导致MySQL Server和client使用的character … Continue reading

Posted in PHP Rocks | 3 Comments

让Smarty在DW里好看

  利用Prefilter重写Smarty delimiters,实现设计时变量tag可见,逻辑tag不可见 设计时:{$variable} <!–{setction name=aaa loop=$bbb}–> …content <!–{/section}–>   实现思想: delimiter 分为design time delimiter和parse time delimiter两种 由Prefilter把design time delimiter重写为parse time delimiter 如果有时候,design time delimiter为可见(非HTML comment tag),但是Smarty tag太长了,也会影响布局。可以引入fake design time delimiter的概念,例如(|和|),在fake design time delimiter间写在DW中看起来爽的,而把真正给Smarty的tag选成HTML coment tag写在后面,利用prefilter在编译之前把所有fake design time delimiter间的内容remove掉

Posted in PHP Rocks | 2 Comments

解决PHP include的路径问题

  解决PHP include的路径问题 Where does include look for file given as a relative path? (from PHP manual) Files for including are first looked in include_path relative to the current working directory and then in include_path relative to the directory of … Continue reading

Posted in PHP Rocks | 2 Comments

Tips that may help you install PHP on Windows

  Tips that may help you install PHP on Windows My software environment: Windows Server 2003 SP1 IIS6 Apache 2.0.54 PHP 4.4.0 PHP 5.0.5     There are many instructions and tutorials on the web talking about the installation of … Continue reading

Posted in PHP Rocks | Leave a comment

嵌套函数定义、与世隔绝的作用域

  在一个php文档里,function的定义可以出现在call之前,也可以出现在其后。然而inner function(function 里面定义的function)并不是这样的,必须“先定义,再调用”。 <?php f1(); function f1() { f2(); function f2() { echo ‘f2’; } } ?> ——————– Fatal error: Call to undefined function: f2() in xxx.php on line 5 这样才行 <?php f1(); function f1() { function f2() { … Continue reading

Posted in PHP Rocks | 4 Comments

PHP session 小结

初学php,自己弄个小结:) Hope it can be helpful!    PHP Session How a session starts? Automatically if session.auto_start is set to 1 Explicitly through session_start() Implicitly through session_register() In your php.ini session.save_path should be set to a valid path, I find sometimes the … Continue reading

Posted in PHP Rocks | 1 Comment