×

smarty用php函数

smarty用php函数(php system函数)

admin admin 发表于2023-03-13 08:40:09 浏览54 评论0

抢沙发发表评论

本文目录一览:

smarty怎么用php函数把字符串转成数组后在计算数组个数

以下是对php中的数组与字符串的转换函数进行了详细的整理汇总,需要的朋友可以参考下

1.将一个字符串转化为数组

str_split()用于将一个字符串转化为数组

语法:

复制代码

代码如下:

str_split(string,length)

SPAN

style="COLOR: #333333"SPAN style="FONT-SIZE: 12px"SPAN

style="FONT-FAMILY:

宋体"///SPAN/SPAN/SPANstring是必须的,是要分割的字符串;SPAN

style="FONT-SIZE: 12px"SPAN style="FONT-FAMILY: 宋体; COLOR:

#333333"SPAN style="LINE-HEIGHT:

28px"

//length是可选的,规定每个数组元素的长度

/SPAN/SPAN/SPAN

tips:

如果 length 小于 1,str_split() 函数将返回

false。

如果 length 大于字符串的长度,整个字符串将作为数组的唯一元素返回。

例子:

复制代码

代码如下:

?php

$str="";

print_r(str_split($str));

?

这个php的smarty函数怎么用?

您使用的是smarty的预过滤器机制,这个是自动调用的。当你通过register_prefilter

把这个函数注册进去后,在display()时smarty会自动去调用来完成页面压缩的。

PHP 中 smarty 要怎么 配置?

1.下载smarty模版放到某目录,我的smarty放在D:\AppServ\www\smarty\目录下;

2.在php函数里面配置:

//配置smarty模版的模版目录,我的放在我的站点blog站点下面:

$_SERVER['Root_Path'] = 'D:/AppServ/www/blog/';

$_SERVER['Base_View'] = $_SERVER['Root_Path'].'/view/';

$smartyRoot = 'D:\AppServ\www\smarty\'; //我的smarty放在此目录下

include($smartyRoot.'libs\Smarty.class.php');

//加载数据库配置信息

$tpl = new Smarty;

$tpl-template_dir = $_SERVER['Base_View'] ;

$tpl-compile_dir = $_SERVER['Root_Path'] . "/ccc/views_c/";

$tpl-config_dir = $_SERVER['Root_Path'] . "/ccc/configs/";

$tpl-cache_dir = $_SERVER['Root_Path'] . "/ccc/cache/";

$tpl-left_delimiter = '!--{';

$tpl-right_delimiter = '}--';

$tpl-caching=false;

$tpl-cache_modified_check=true;

$tpl-cache_lifetime=600;

如果第二部失败,考虑下面问题:

目录权限设置问题:

$tpl-compile_dir = $_SERVER['Root_Path'] . "/ccc/views_c/";

$tpl-config_dir = $_SERVER['Root_Path'] . "/ccc/configs/";

$tpl-cache_dir = $_SERVER['Root_Path'] . "/ccc/cache/";

这些目录都有相应的读写权限

PHP模板中smarty_block函数的用法

Smarty末班引擎中提供了三种插件支持,分别是block(块),function(函数),modifier(调节器),用户可以自己扩展。

block:是一种非常灵活的高级插件,这种插件在模板中使用时需要成对出现,Smarty内置的block插件例如section,foreach等,使用格式为:

{section name="customer" loop="$data"}

li内容/li

{/section}

function:他的作用类似于函数,在模板中使用无需成对出现,系统内置的如include,格式为:{include file="web/index.tpl"}。

modifier:调节器是用于对变量进行修饰的,内置的调节器如:truncate(截取字符长度),date_format(格式化时间),使用格式为:

{$nowtime|date_format:"%Y-%m-%d"}

在来分析下你的问题:

-----------------------------------------------------------------------

你提问中的这个就应当属于block插件,其中blockname是个插件名,此插件不包含任何参数。

{blockname}!--插件开始标签--

没有缓存的:{$smarty.now}!--插件输入的内容,Smarty.now为全局函数,意思是输出当前时间--

{/blockname}!--插件结束标签--

thinkphp中如何用内置的smarty调用php中自定义的函数?

可以自己写个smarty插件,我以前写过,你根据smarty手册上的提示也可以写出来的。相信自己!

这是我以前写的,转换时间的:

?php

/**

 *时间显示,将Unix时间或普通时间和转为生活时间用语

 */

function smarty_modifier_life_time($string)

{

if(strpos($string, '-') || strpos($string, '.'))

{

$string = strtotime($string);

}

$res = time() - $string;

if($res = 60)

{

return '1分钟前';

}else if($res = 3600){

if($res = 1800  $res = 1800+60) return '半小时前';

return floor($res/60).'分钟前';

}else if($res = 3600*24){

if($res = 3600*12  $res = 3600*12+3600) return '半天前';

return floor($res/3600).'小时前';

}else if($res = 3600*24*30){

if($res = 3600*24*15  $res = 3600*24*15+3600*24) return '半个月前';

return floor($res/(3600*24)).'天前';

}else if($res = 3600*24*30*365){

if($res = 3600*24*30*6  $res = 3600*24*30*6+3600*24*30) return '半年前';

return floor($res/(3600*24*30)).'月前';

}else{

if($res = 3600*24*30*365  $res = 3600*24*30*365+3600*24*30) return '一年前';

return date('Y-m-d H:i', $string);

}

}

?