在smarty中使用print_r函數 打印異常
實際上在smarty中不需要使用print_r函數,但smarty中支持php的內置函數 ? 按理說也是可以正常使用的,于是...測試了下
<?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}
打印結果是 a1
為何?不應該是a嗎?
2016-12-27
納悶之余,去翻看了一下smarty編譯后的php程序發現了如下代碼:
原來是prinr_r打印后返回了一個true,后面的echo又跟上來打印true,php自動將true轉變成了1給打印了。。
...
解決了