I like the filtering capabilities of the Zend Framework, but for some reason there doesn't seem to be a string to title case filter (though there is a string to upper and string to lower). So here it is:
PHP:
-
<?php
-
-
/**
-
* @see Zend_Filter_Interface
-
*/
-
require_once 'Zend/Filter/Interface.php';
-
-
/**
-
* Convert a string to titlecase.
-
*
-
* Seemingly missing from the core Zend distribution.
-
*/
-
class StringToTitle implements Zend_Filter_Interface
-
{
-
/**
-
* Encoding for the input string
-
*
-
* @var string
-
*/
-
protected $_encoding = null;
-
-
/**
-
* Set the input encoding for the given string
-
*
-
* @param string $encoding
-
* @throws Zend_Filter_Exception
-
*/
-
public function setEncoding($encoding = null)
-
{
-
require_once 'Zend/Filter/Exception.php';
-
throw new Zend_Filter_Exception('mbstring is required for this feature');
-
}
-
$this->_encoding = $encoding;
-
}
-
-
/**
-
* Defined by Zend_Filter_Interface
-
*
-
* Returns the string $value, converting characters to titlecase as necessary
-
*
-
* @param string $value
-
* @return string
-
*/
-
public function filter($value)
-
{
-
if ($this->_encoding) {
-
}
-
}
-
}




0 Responses to “StringToTitle filter”
Leave a Reply
You must login to post a comment.