在smarty中使用print_r函數(shù) 打印異常
實(shí)際上在smarty中不需要使用print_r函數(shù),但smarty中支持php的內(nèi)置函數(shù) ? 按理說也是可以正常使用的,于是...測試了下
<?php require?'./libs/Smarty.class.php'; $smarty?=?new?Smarty(); $smarty->setTemplateDir('tpl'); $smarty->setCompileDir('template_c'); $smarty->setCacheDir('cache'); $smarty->caching?=?false; $smarty->cache_lifetime?=?120; $smarty->display('test.tpl'); ?>
test.tpl中的代碼: {"a"|print_r}
打印結(jié)果是 a1
為何?不應(yīng)該是a嗎?
2016-12-27
納悶之余,去翻看了一下smarty編譯后的php程序發(fā)現(xiàn)了如下代碼:
原來是prinr_r打印后返回了一個(gè)true,后面的echo又跟上來打印true,php自動將true轉(zhuǎn)變成了1給打印了。。
...
解決了