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_StringTruncate Component Proposal

Proposed Component Name Zend_Filter_StringTruncate
Developer Notes
Proposers Thomas Weidner
Zend Liaison TBD
Revision 1.0 - 8 August 2009: Initial Draft. (wiki revision: 8)

Table of Contents

1. Overview

Zend_Filter_StringTruncate is a filter which truncates strings, regardless of their content.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • This component will truncate strings at a given length
  • This component will also handle multibyte strings

4. Dependencies on Other Framework Components

  • Zend_Filter_Interface
  • Zend_View_Helper_Abstract

5. Theory of Operation

This filter truncates strings to a given length. It's the reverse filter for the StringPad Filter.
For simplicity this filter also adds 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_StringTruncate
  • Zend_View_Helper_StringTruncate

8. Use Cases


Truncate a string at 6 chars


Truncate a string at 6 chars, using ending chars


Truncate a string at 6 chars, using ending chars and additionally get the truncated content


Truncate a string at 6 chars but from the other side

9. Class Skeletons



Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Mar 13, 2010

    <p>I like the proposal. But an option to truncate the string in the middle would be nice too.</p>

    <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
    $filter->filter( 'This is a test string' );
    // returns 'This ... ring' or 'This...ring' or something similar

  2. Jul 11, 2010

    <p>Might a better name for this component be Zend_Filter_Truncate?</p>

    1. Jul 12, 2010

      <p>No, because it does not truncate numbers or files or arrays. It works only on strings.</p>

      <p>It might be better to have a own "Zend_Filter_String_" subtree, but as long as all other string filters are located directly under Zend_Filter I see no reason to add a new subtree for a single filter.</p>

      <p>This is something which could be rethought for 2.0.</p>

  3. Jul 28, 2010

    <p>Thomas; would this component also be able to only truncate a string on a space/line-ending/etc with an optional grace-length?</p>

    1. Jul 30, 2010

      <p>No it will not.<br />
      I was said to detach this functionallity into a own proposal which you can find here:
      <a class="external-link" href=""></a></p>

  4. 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 suggests the functionality of the WordTruncate is implemented in the StringTruncate component as well.</p></ac:rich-text-body></ac:macro>

    1. Aug 03, 2010

      <p>Note that I was explicitly said to detach this functionallity into two filters. It was the decision of my liaison</p>

      1. Aug 12, 2010

        <p>The CR Team makes a good argument for incorporating the WordTruncate functionality in this filter, and my team agrees with them. Please incorporate a "words" option, which, if specified, will supersede any provided "length" option, and specify the number of words to retain in the filtered string.</p>