Package Home

Zend Framework 2 Documentation (Manual)

PHK Home

File: /_sources/modules/zend.filter.string-trim.txt

Size:1489
Storage flags:no_autoload,compress/gzip (40%)

.. _zend.filter.set.stringtrim:

StringTrim
----------

This filter modifies a given string such that certain characters are removed from the beginning and end.

.. _zend.filter.set.stringtrim.options:

Supported Options
^^^^^^^^^^^^^^^^^

The following options are supported for ``Zend\Filter\StringTrim``:

- **charlist**: List of characters to remove from the beginning and end of the string. If this is not set or is
  null, the default behavior will be invoked, which is to remove only whitespace from the beginning and end of the
  string.

.. _zend.filter.set.stringtrim.basic:

Basic Usage
^^^^^^^^^^^

A basic example of usage is below:

.. code-block:: php
   :linenos:

   $filter = new Zend\Filter\StringTrim();

   print $filter->filter(' This is (my) content: ');

The above example returns 'This is (my) content:'. Notice that the whitespace characters have been removed.

.. _zend.filter.set.stringtrim.types:

Default Behavior
^^^^^^^^^^^^^^^^

.. code-block:: php
   :linenos:

   $filter = new Zend\Filter\StringTrim(':');
   // or new Zend\Filter\StringTrim(array('charlist' => ':'));

   print $filter->filter(' This is (my) content:');

The above example returns 'This is (my) content'. Notice that the whitespace characters and colon are removed. You
can also provide a Traversable or an array with a 'charlist' key. To set the desired character list after
instantiation, use the ``setCharList()`` method. The ``getCharList()`` return the values set for charlist.



For more information about the PHK package format: http://phk.tekwire.net