ZF-6053: Add new string pad filter

Issue Type: New Feature Created: 2009-03-18T02:15:11.000+0000 Last Updated: 2009-12-07T15:09:52.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Václav Vaník (dimmu) Assignee: Thomas Weidner (thomas) Tags: - Zend_Filter

Related issues: Attachments: - StringPad.php


Class could be something like:

setLength($length); $this->setString($string); $this->setType($type); } /\*\* \* Retrieve padding length \* \* @return int \*/ public function getLength() { return $this->\_length; } /\*\* \* Retrieve padding characters \* \* @return string \*/ public function getString() { return $this->\_string; } /\*\* \* Retrieve padding type \* \* @return string \*/ public function getType() { return $this->\_type; } /\*\* \* Set padding length \* \* @param int $length \* @return Zend\_Filter\_StringPad \*/ public function setLength($length) { $this->\_length = (int) $length; return $this; } /\*\* \* Set padding characters \* \* @param string $string \* @return Zend\_Filter\_StringPad \*/ public function setString($string) { $this->\_string = (string) $string; return $this; } /\*\* \* Set padding type \* \* @param string $type \* @return Zend\_Filter\_StringPad \*/ public function setType($type) { switch ($type) { case self::TYPE\_BOTH: case self::TYPE\_LEFT: case self::TYPE\_RIGHT: $this->\_type = $type; break; default: throw new Zend\_Filter\_Exception('Padding type is invalid'); } return $this; } /\*\* \* Converts our pad type consts to STR\_PAD\_\* consts \* \* @return string \*/ protected function \_getType() { switch ($this->\_type) { case self::TYPE\_LEFT: return STR\_PAD\_LEFT; case self::TYPE\_RIGHT: return STR\_PAD\_RIGHT; default: return STR\_PAD\_BOTH; } } /\*\* \* Pad a string to a certain length with another string \* \* @param string $value \* @return string \*/ public function filter($value) { $pad = ''; if (strlen($value) > 0) { $pad = str\_pad($value, $this->\_length, $this->\_string, $this->\_getType()); } return $pad; } } ?>


Posted by Ben Scholzen (dasprid) on 2009-03-18T02:21:35.000+0000

If so, it should use Zend_Text_MultiByte::strPad() to allow correct padding of non-ascii strings.

Posted by Václav Vaník (dimmu) on 2009-03-18T02:55:52.000+0000

Multibyte-safe version of the Zend_Filter_StringPad

Posted by Václav Vaník (dimmu) on 2009-03-18T02:57:47.000+0000

Oh Ben, you are right. I added the multibyte-safe version. I think it is not necessary to use Zend_Text_MultiByte class because of dependency.

Posted by Thomas Weidner (thomas) on 2009-04-17T00:00:51.000+0000

A proposal where this feature is part of has been added to Wiki. Waiting for Recommendation and Response from Zend since 15.April.2009

Posted by Thomas Weidner (thomas) on 2009-12-07T15:09:52.000+0000

Closing as "needs proposal". The proposal is already written and waiting for acceptance. See here for details and vote for it:…

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.