Skip to the content
Documentation

pad

No ratings yet

Summary

Returns a lengthened version of the input string.

Usage

input|pad( length [, padding ] )

Parameters

Name Type Description Required
length integer The desired length of the string. Yes.
padding character Custom character to be used for padding. No.

Returns

A padded version of the input string.

Description

This operator makes sure that the input string is at least "length" characters long by inserting extra characters at the end. It is possible to specify a custom character using the "padding" parameter (default is space). The operator returns a padded version of the input string.

Examples

Example 1
{'Too short!'|pad( 15 )}

The following string will be produced: "Too short! ".

Example 2
{'Too short!'|pad( 16, '-' )}

The following string will be produced: "Too short!------".

Changed in Exponential 6.0.15

The named parameters of the operator pad in Exponential 6.0.15 (eZTemplateStringOperator::namedParameterList(), lib/eztemplate/classes/eztemplatestringoperator.php), by position:

Position 6.0.15 (name in the code) This page
1 desired_length, required: No. length, required: Yes.

Contributors

Comments (2 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. How to pad left?

    Massimiliano Bariola ·

    Is there a way to left-pad a string without having to reverse|pad|reverse it ?

  2. How to pad left .. I found out how

    Massimiliano Bariola ·

    This requires some lateral thinking:
    for example, to pad a 0-99 $number to 00-99:
    0|pad(2, $number)
    I don't know what happens if $number is over 2 digits tho'. didn't try it.

Comments

Add a comment

Comments are read by a moderator before they appear.