变量调节器(实例)

来源:互联网 发布:windows核心编程 源码 编辑:程序博客网 时间:2024/05/18 01:49

variable_modifers.php

<?php
include '../libs/Smarty.class.php';
$smarty = new Smarty();
$smarty->template_dir="../demo/templates";
$smarty->compile_dir="../demo/templates_c";

$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
$string = "hello world. \n hello everyone! ";
$smarty->assign("cap",$string);
$smarty->assign('num',123.12345);
$smarty->display('variables_modifiers.tpl');

variable_modifers.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=utf-8" />
<title>测试变量调节器</title>
</head>

<body>
Capitalize功能演示:<br />
原变量内容:<{$cap|escape:"htmlall"|nl2br}><br />
应用后内容:<{$cap|capitalize}><br />
<hr />
count_characters功能演示:<br />
<{$cap}>的字符个数(不计空格):<{$cap|count_characters}><br />
<{$cap}>的字符个数(计空格):<{$cap|count_characters:true}>
<hr />
cat功能演示:<br />
给字符串<{$cap}>连接***之后是:<{$cap|cat:"***"}><br />
<hr />
count_paragraphs功能演示:<br />
<{ $cap }>的段落个数是:<{$cap|count_paragraphs}>
<hr />
count_sentences功能演示:<br />
<{$cap}>中的句数为:<{$cap|count_sentences}><br />
<hr />
count_words功能演示:<br />
<{$cap}>的总单词数是:<{$cap|count_words}>
<hr />
data_format功能演示:<br />
当前系统时间为:<{ $smarty.now|date_format:"%Y-%m-%d 星期:%a %H:%M:%S"}>
<hr />
string_format功能演示:<br />
<{$num}>通过%m(m表示共有多少字符)d格式化:<{$num|string_format:"%d"}><br />
<{$num}>通过%m.nf格式化一个实数:<{$num|string_format:"%6.2f"}>&nbsp;&nbsp;<{$num|string_format:"%.3f"}><br />
<{$num}>通过%e格式化一个实数:<{$num|string_format:"%e"}>&nbsp;&nbsp;  <{$num|string_format:"%3.1e"}>
<hr />
<{$cap|indent:10:"&nbsp;"}>
<hr />
<{$cap|replace:"hello":"hi"}>
<hr />
truncate功能演示:<br />
<{$cap|truncate:6}><br />
<{$cap|truncate:6:"--"}><br />
<{$cap|truncate:6:"":true}><br />
</body>
</html>


输出:

    Capitalize功能演示:
原变量内容:hello world.
hello everyone!
应用后内容:Hello World. Hello Everyone!


count_characters功能演示:
hello world. hello everyone! 的字符个数(不计空格):25
hello world. hello everyone! 的字符个数(计空格):31
cat功能演示:
给字符串hello world. hello everyone! 连接***之后是:hello world. hello everyone! ***

count_paragraphs功能演示:
hello world. hello everyone! 的段落个数是:2
count_sentences功能演示:
hello world. hello everyone! 中的句数为:1

count_words功能演示:
hello world. hello everyone! 的总单词数是:4
data_format功能演示:
当前系统时间为:2012-11-12 星期:Mon 19:05:42
string_format功能演示:
123.12345通过%m(m表示共有多少字符)d格式化:123
123.12345通过%m.nf格式化一个实数:123.12  123.123
123.12345通过%e格式化一个实数:1.231235e+2   1.2e+2
          hello world.            hello everyone!
hi world. hi everyone!
truncate功能演示:
hel...
hell--
hello



原创粉丝点击