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

Creeping towards PHP — global tricked me

global tricked meTesting environment:php 4.3.11Smarttemplate 1.0.2 02.04.2003 While adding the file inclusion support for Smarttemplate, I found it problematic to use multiple Smarttemplate in a sigle PHP script. With the help of almighty Google, I knew a way to solve this … Continue reading

Posted in PHP Rocks | 2 Comments

Regular Expression the first touch

The almighty regular expression which is not supported by Flash but found in Central is now serving me in my new love — PHP. 为了建立网站数据库中的countries表,我进入Microsoft .NET Passport的注册页面。里面的国家(地区)项包含了全世界的各个国家,不过 是个HTML的select+option,不能直接用。ViewSource后将select控件部门的代码存入countries.txt。我想用php的regular expression。 //countries.txt里的内容如下 <option value="AL" id="AL">阿尔巴尼亚 <option value="DZ" id="DZ">阿尔及利亚 <option value="AF" id="AF">阿富汗 <!– … Continue reading

Posted in PHP Rocks | 2 Comments

Starting a new life with PHP & MySQL

C#固然可亲,AS固然可爱,但是大公司门有自己的打算。譬如Microsoft,为我们做好了大量服务器端控件,说是为了streamline web development,强大的Visual Studio 2005,说是要让程序员早点下班。但是,还有一样东西,允许你用EditPlus,用HTML模版技术,直击HTML表示的最底层。毕竟,指望服务器为我们产生完美的HTML让我们丧失了太多的乐趣!ASP.NET产生的HTML虽然工整,但繁杂得不行,还有一片一片的hidden field。很多开发人员直接由VS做网页了,因为在DW和VS间斡旋令人痛苦。在DW里写的客户端脚本的一个错误,可能导致ASP.NET生成的客户端脚本得不到执行,于是数据无法提交。在譬如Macromedia,AS 2.0的OO的确吸引人,V2的构架的确像个Framework,然而权衡得失,令人扼腕痛惜!偶然看到一些很酷很酷的动画,玄妙之至,下载下来反编,竟是Flash 4的句法!让我来实现,难免要over-design,然而x KB的精彩,得益于Flash本身的灵活,正是其优势所在。用Flash开发App,写类套用模式,须事先综合权衡,仔细评估,开发能力不是Flash的强项,也不是Flash的救命稻草。优秀的Flash程序往往是AS1 和 AS2的结合,AS1来控制流程,AS2来实现模块化的功能。MM要怎样决定Flash的命运是我管不了的,但我希望let it be Flash!轻快短小,在让传统程序员摸不着头脑的timeline上穿梭自如,恰是Flash崛起的法宝。至于Screen和Slide,是要拿Flash跟VB和PPT比么? PHP5来了!Luar在blog上说:PHP發明者Rasmus Lerdorf,他對PHP5在面向對象上做的改進:「PHP的用戶有很多種,但我想絕大部分的用戶其實不是那麼在乎面向對象,僅僅是一小部分的用戶叫囂著要加入面向對象的支持,因為他們非常在乎面向對象的特性…雖然他們需要PHP能像Java那樣完全的面向對象,但我們不打算這樣做,我們僅僅是改進PHP以前不足的地方。」模仿Rasmus Lerdorf的言論:「ActionScript的用戶有很多鍾,但我想絕大部分的用戶其實不是那麼在乎面向對象,最常用到仍然是ActionScript 1.0。」 我想,这正是我们所思考的问题,在疯狂跟随大公司的新技术时,倒是该多想想自己在做什么,真的需要那么庞大的"构架"、"解决方案"吗? 富有创造力的群体,不应该是公司产品的Assemblers!Flash不能载入gif?那好,我用php做个代理在中间转换一次。V2的DataGrid里的极有用属性是私有的?那好,我用["xxx"]!HTTP无状态?好,我们早就用hidden field了,还等着ASP.NET来沾沾自喜的宣扬?程序以人为中心,不是束缚思想的牢笼! 我从今天开始学习PHP,体会 DataBase db = new DataBaseFactory.CreateDataBase();string sqlCommand = "Select * From Customers";DBCommandWrapper dbCommandWrapper = db.GetSqlStringCommandWrapper(sqlCommand);IDataReader dataReader = db.ExecuteReader(dbCommandWrapper);StringBuilder readerData … Continue reading

Posted in PHP Rocks | Leave a comment