一、变量输出 (重点)
1.标量输出
2.数组输出
{$name[1]}
{$name['k2']}
{$name.k1}
3.对象输出
{$name:k}
{$name->k}
二、系统变量
{$Think.get.id}
三、使用函数
{$name|strtoupper} 生成的编译后文件是 <?php echo (strtoupper($name)); ?>
{$name|date='Y m d H:i:s',###}
四、默认值
{$name|default='这里是默认值'}
五、运算符
+ - * / % ++ --
{$name++}
perl 的一些数据结构:
zjzc01:/root/test# cat s1.pl
##数组
print "数组
";
@arr=qw/a1 a2 a3 a4/;
print $arr[0]."
";
print $arr[1]."
";
print "hash
";
##hash
%hash=(a=>1,b=>2,c=>3);
print $hash{a}."
";
print $hash{b}."
";
##数组引用
print "数组引用
";
$arr=[a1,a2,a3,a4];
print $arr->[0]."
";
print $arr->[1]."
";
##hash引用
print "hash 引用
";
$hash={a=>1,b=>2,c=>3};
print $hash->{a}."
";
print $hash->{b}."
";
zjzc01:/root/test# perl s1.pl
数组
a1
a2
hash
1
2
数组引用
a1
a2
hash 引用
1
2
//关联数组输出:
<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
//调用index.html模板文件
//name表示标识
$arr=array('k1'=>'scan1','k2'=>'scan2');
$this->assign('name',$arr);
$this->display();
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
{$name['k1']}!!
{$name.k1}!!
</body>
</html>
////输出对象
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp2/ThinkPHP/Extend/Library/ORG
$ ls
Crypt My Net Util
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp2/ThinkPHP/Extend/Library/ORG
新建my 文件夹
<?php
class test{
public $k='liu!';
}
?>
<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
//调用index.html模板文件
//name表示标识
//加载第三方类
import ('ORG.My.test');
//$arr=array('k1'=>'scan1','k2'=>'scan2');
$obj=new test;
$this->assign('name',$obj);
$this->display();
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
{$name:k}
</body>
</html>
{$name:k}
{$name->k} 对象下面的成员属性
// 控制器接收GET传值,分配给name标示
<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
public function index(){
$n=$_GET['name'];
//调用index.html模板文件
//name表示标识
//加载第三方类
import ('ORG.My.test');
//$arr=array('k1'=>'scan1','k2'=>'scan2');
//$obj=new test;
$this->assign('name',$n);
$this->display();
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
{$name}</br>
</body>
</html>
//利用系统变量
{$name}</br>
{$Think.get.name}</br>
//php编译后文件:
$ pwd
/cygdrive/c/wamp/www/thinkphp2/Home/Runtime/Cache
Administrator@QCEE61NZ66FEX2D /cygdrive/c/wamp/www/thinkphp2/Home/Runtime/Cache
$ ls
7e4848229090366086cc7eeb3bfc0798.php 9885ecc411f90bec36756701bd64bb4a.php
<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus庐">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<?php echo ($name); ?></br>
<?php echo ($_GET['name']); ?></br>
<?php echo (strtoupper($name)); ?>
<?php echo (session('aa')); ?></br>
</body>
</htm
//编译后文件:
<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus庐">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<?php echo ($name); ?></br>
<?php echo ($_GET['name']); ?></br>
<?php echo (date('Y m d H:i:s',$name)); ?>
<?php echo (session('aa')); ?></br>
</body>
</html