Skip to content

indent

indent 用于在每行上缩进字符串,默认为 4 个字符。作为可选参数,您可以指定要缩进的字符数。作为可选的第二个参数,您可以指定用于缩进的字符。例如:使用 "\t" 来表示一个制表符。

基本用法

{$myVar|indent:4}

参数

参数位置 类型 必需 默认值 描述
1 整数 4 指定要缩进的字符数
2 字符串 (一个空格) 用于缩进的字符

示例

<?php

$smarty->assign('articleTitle',
                'NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.'
                );

模板如下:

{$articleTitle}

{$articleTitle|indent}

{$articleTitle|indent:10}

{$articleTitle|indent:1:"\t"}

输出结果如下:

NJ judge to rule on nude beach.
Sun or rain expected today, dark tonight.
Statistics show that teen pregnancy drops off significantly after 25.

    NJ judge to rule on nude beach.
    Sun or rain expected today, dark tonight.
    Statistics show that teen pregnancy drops off significantly after 25.

          NJ judge to rule on nude beach.
          Sun or rain expected today, dark tonight.
          Statistics show that teen pregnancy drops off significantly after 25.

        NJ judge to rule on nude beach.
        Sun or rain expected today, dark tonight.
        Statistics show that teen pregnancy drops off significantly after 25.

另请参阅 stripwordwrapspacify