本文實例講述了smarty自定義函數htmlcheckboxes用法。分享給大家供大家參考。具體如下:
訪問文件:index.php:
復制代碼 代碼如下:<?php
require_once('libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->setTemplateDir($_SERVER['DOCUMENT_ROOT']."/php/templates/");
$smarty->setCompileDir($_SERVER['DOCUMENT_ROOT']."/php/templates_c/");
$smarty->setCacheDir($_SERVER['DOCUMENT_ROOT']."/php/cache/");
$smarty->caching = false;
$smarty->assign('cust_ids',array(1000,1001,1002,1003));
$smarty->assign('cust_name',array("喜洋洋","美洋洋","懶洋洋","哈哈哈"));
$smarty->assign('customer_id',1001);
$smarty->display("temp.htm");
?>
模板文件:temp.htm
復制代碼 代碼如下:{html_checkboxes values=$cust_ids output=$cust_name selected=$customer_id}
測試結果:utf-8下顯示正常,但文件編碼為ANSI時,中文不能顯示。
希望本文所述對大家的php程序設計有所幫助。