Smarty,计算数组键字符串的长度?

问题描述 投票:0回答:3

{$smarty.post.email}
输出“[电子邮件受保护]

{$smarty.post.email|count}
输出“1”而不是“14”——字符串长度。

{$smarty.post.email[0]|count}
也输出“1”。

如何找到名为“email”的密钥的长度?

php count smarty
3个回答
2
投票

使用

{$smarty.post.email|count_characters:true}

来源:http://www.smarty.net/docsv2/en/language.modifier.count.characters.tpl


0
投票
$count = strlen($smarty.post.email);

$count = strlen($smarty[post][email]);

strlen 返回字符串的长度。键名称是字符串。

count 返回数组中键的数量。


0
投票

使用

count_characters
代替
count
:

{$smarty.post.email|count_characters}
输出“14”

© www.soinside.com 2019 - 2024. All rights reserved.