Smarty的变量调节器

一 代码

index.php
<?php
	include_once "../config.php";
	$str1 = '这是一个实例。';
	$str2 = "\n图书->计算机类->php\n书名:《php从入门到精通》";
	$str3 = "\n价格:¥59/本。";
	$smarty->assign('title','使用变量修饰方法');
	$smarty->assign('str',$str1.$str2.$str3.$str4);
	$smarty->display('5/index.tpl');
?>
 
index.tpl
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>{$title}</title>
<link rel="stylesheet" href="../css/style.css" />
</head>
<body>
原文:{$str}
<p>
变量中的字符数(包括空格):{$str|count_characters:true}
<br />
使用变量修饰方法后:{$str|nl2br|upper}
</body>
</html>
 
二 运行结果
原文:这是一个实例。 图书->计算机类->php 书名:《php从入门到精通》 价格:¥59/本。

变量中的字符数(包括空格):76 
使用变量修饰方法后:这是一个实例。
图书->计算机类->PHP
书名:《PHP从入门到精通》
价格:¥59/本。

猜你喜欢

转载自cakin24.iteye.com/blog/2380006