Home > Backend Development > PHP Tutorial > smarty中truncate截取字符的疑问

smarty中truncate截取字符的疑问

WBOY
Release: 2016-06-06 20:07:55
Original
925 people have browsed it

smarty中truncate和spacify组合使用后截取字符的疑问
模板文件index.tpl中的代码如下:

<code> 
 <br>
</code>
Copy after login
Copy after login

index.php中的代码如下:

<code>$smarty->assign('articleTitle', 'Smokers are Productive, but Death Cuts Efficiency.');
$smarty->display('index.tpl');
</code>
Copy after login
Copy after login

代码运行的结果为:
S m o k e r s a r e P r...

但是根据我的思考如下的这段代码:

<code>  <br> 
</code>
Copy after login
Copy after login

(1)先根据spacify在字符间插入空格得到:S m o k e r s a r e P r o d u c t i v e
(2)然后使用truncate:5:"..."截取(1)中的字符结果为:
S m o k e r s a r e P r o d...
但是由于truncate默认是按单词截取的所以最终的结果应该为:
S m o k e r s a r e... 这与程序运行的结果不一样????

回复内容:

smarty中truncate和spacify组合使用后截取字符的疑问
模板文件index.tpl中的代码如下:

<code> 
 <br>
</code>
Copy after login
Copy after login

index.php中的代码如下:

<code>$smarty->assign('articleTitle', 'Smokers are Productive, but Death Cuts Efficiency.');
$smarty->display('index.tpl');
</code>
Copy after login
Copy after login

代码运行的结果为:
S m o k e r s a r e P r...

但是根据我的思考如下的这段代码:

<code>  <br> 
</code>
Copy after login
Copy after login

(1)先根据spacify在字符间插入空格得到:S m o k e r s a r e P r o d u c t i v e
(2)然后使用truncate:5:"..."截取(1)中的字符结果为:
S m o k e r s a r e P r o d...
但是由于truncate默认是按单词截取的所以最终的结果应该为:
S m o k e r s a r e... 这与程序运行的结果不一样????

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template