1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 4.3.2 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
19 * CodeIgniter Inflector Helpers
21 * @package CodeIgniter
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/helpers/directory_helper.html
29 // --------------------------------------------------------------------
34 * Takes a plural word and makes it singular
40 if ( ! function_exists('singular'))
42 function singular($str)
44 $str = strtolower(trim($str));
45 $end = substr($str, -3);
49 $str = substr($str, 0, strlen($str)-3).'y';
51 elseif ($end == 'ses')
53 $str = substr($str, 0, strlen($str)-2);
57 $end = substr($str, -1);
61 $str = substr($str, 0, strlen($str)-1);
69 // --------------------------------------------------------------------
74 * Takes a singular word and makes it plural
81 if ( ! function_exists('plural'))
83 function plural($str, $force = FALSE)
85 $str = strtolower(trim($str));
86 $end = substr($str, -1);
90 // Y preceded by vowel => regular plural
91 $vowels = array('a', 'e', 'i', 'o', 'u');
92 $str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies';
110 // --------------------------------------------------------------------
115 * Takes multiple words separated by spaces or underscores and camelizes them
121 if ( ! function_exists('camelize'))
123 function camelize($str)
125 $str = 'x'.strtolower(trim($str));
126 $str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
127 return substr(str_replace(' ', '', $str), 1);
131 // --------------------------------------------------------------------
136 * Takes multiple words separated by spaces and underscores them
142 if ( ! function_exists('underscore'))
144 function underscore($str)
146 return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
150 // --------------------------------------------------------------------
155 * Takes multiple words separated by underscores and changes them to spaces
161 if ( ! function_exists('humanize'))
163 function humanize($str)
165 return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
170 /* End of file inflector_helper.php */
171 /* Location: ./system/helpers/inflector_helper.php */