PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Zend_Filter_Inflector

Zend_Filter_Inflector is a general purpose tool for rules-based inflection of strings to a given target.

As an example, you may find you need to transform MixedCase or camelCasedWords into a path; for readability, OS policies, or other reasons, you also need to lower case this, and you want to separate the words using a dash ('-'). An inflector can do this for you.

Zend_Filter_Inflector implements Zend_Filter_Interface; you perform inflection by calling filter() on the object instance.

Example 438. Transforming MixedCase and camelCaseText to another format

<?php
$inflector 
= new Zend_Filter_Inflector('pages/:page.:suffix');
$inflector->setRules(array(
    
':page'  => array('Word_CamelCaseToDash''StringToLower'),
    
'suffix' => 'html'
));

$string   'camelCasedWords';
$filtered $inflector->filter(array('page' => $string));
// pages/camel-cased-words.html

$string   'this_is_not_camel_cased';
$filtered $inflector->filter(array('page' => $string));
// pages/this_is_not_camel_cased.html

Zend Framework