Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_Filter_StringPad Component Proposal

Proposed Component Name Zend_Filter_StringPad
Developer Notes
Proposers Thomas Weidner
Zend Liaison TBD
Revision 1.0 - 23 July 2009: Initial Draft. (wiki revision: 7)

Table of Contents

1. Overview

Zend_Filter_StringPad is a filter which allows to extend strings to a specific length.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • This component will correctly handle multi byte strings.
  • This component will support the same parameters as PHP's own str_pad method.

4. Dependencies on Other Framework Components


5. Theory of Operation

This filter extends given strings to the wished length. It accepts and other string for extension/padding and default to whitespace if non is given.
It also supports extension from left, right or both sides.
For simplicity this component adds also a view helper which makes use of this filter.

6. Milestones / Tasks

  • Milestone 1: [DONE] Proposal finished
  • Milestone 2: Proposal accepted
  • Milestone 3: Working implementation
  • Milestone 4: Unit tests
  • Milestone 5: Documentation
  • Milestone 6: Moved to core

7. Class Index

  • Zend_Filter_StringPad
  • Zend_View_Helper_StringPad

8. Use Cases


Extends a string to 15 chars


Extends a string to 15 chars, using another pad char


Extends a string to 15 chars, using another pad char and another direction

9. Class Skeletons



Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Aug 05, 2009



    <p>Voted down because this filter is a wrapper of the str_pad() function. This is the same as creating a wrapper of the strtolower() function or any other PHP function. what's the purpose of doing something like that?</p>

    1. Aug 05, 2009

      <p>There is an existing Zend_Filter_StringToLower.<br />
      For this decission there are 2 reasons:</p>

      <p>1.) str_pad and co are not binary aware... they can not handle UTF-8</p>

      <p>2.) many ZF components make use of filters. For a user it's simpler and more common to call</p>
      <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[addFilter('StringPad', 'xxx');]]></ac:plain-text-body></ac:macro>

      <p>than calling</p>
      <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[addFilter('Callback', 'str_pad', array('xxx'));]]></ac:plain-text-body></ac:macro>

      1. Aug 07, 2009


        <p>I don't recall anyone complaining about str_pad not being able to handle encodings properly in the last 10 years or so. If you beleive the str_pad function is buggy, then you should create a proposal or commit a patch to the php project instead. But not create a wrapper for each php function. </p>

        <p>The same goes for strtolower, and similar classes added to the framework.</p>

        1. Aug 28, 2009

          <p>So Zend_Filter, Zend_Validate, Zend_Date, Zend_Currency, Zend_Memory, Zend_Cache are some of the components which should be erased in your opinion because php has functions which work partitially similar ?</p>

          <p>I thought the reason for proposals is simplicity and usability for ZF ?</p>

  2. Jul 28, 2010

    <p>Thomas, could you please give a url where the multibyte limitation in php's native str_pad() function is described?</p>

    1. Jul 30, 2010

      <p>See this long opened bug here: <a class="external-link" href=""></a><br />
      But this is not the main reason for this proposal... just one of the things which could be done with it.</p>

      1. Jul 30, 2010

        <p>If that is not the main reason for this proposal, what is? One can always call str_pad() through the callback filter after all.</p>

  3. Aug 03, 2010

    <ac:macro ac:name="note"><ac:rich-text-body><p><strong>Community Review Team Recommendation</strong></p>

    <p>The CR Team advises that this proposal be approved, and would like to have clarification on option names as they may cause confusion.</p></ac:rich-text-body></ac:macro>

    1. Aug 03, 2010

      <p>'length' => length of string to pad (integer)<br />
      'type' => type of padding to use (constant/integer)<br />
      'pad' => string used to pad (string)<br />
      'truncate' => if pad string is allowed to be truncated when it extends length (boolean)</p>