1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, 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)
45 $end = substr($str, -3);
47 $str = preg_replace('/(.*)?([s|c]h)es/i','$1$2',$str);
49 if (strtolower($end) == 'ies')
51 $str = substr($str, 0, strlen($str)-3).(preg_match('/[a-z]/',$end) ? 'y' : 'Y');
53 elseif (strtolower($end) == 'ses')
55 $str = substr($str, 0, strlen($str)-2);
59 $end = strtolower(substr($str, -1));
63 $str = substr($str, 0, strlen($str)-1);
71 // --------------------------------------------------------------------
76 * Takes a singular word and makes it plural
83 if ( ! function_exists('plural'))
85 function plural($str, $force = FALSE)
88 $end = substr($str, -1);
90 if (preg_match('/y/i',$end))
92 // Y preceded by vowel => regular plural
93 $vowels = array('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U');
94 $str = in_array(substr($str, -2, 1), $vowels) ? $str.'s' : substr($str, 0, -1).'ies';
96 elseif (preg_match('/h/i',$end))
98 if(preg_match('/^[c|s]h$/i',substr($str, -2)))
107 elseif (preg_match('/s/i',$end))
123 // --------------------------------------------------------------------
128 * Takes multiple words separated by spaces or underscores and camelizes them
134 if ( ! function_exists('camelize'))
136 function camelize($str)
138 $str = 'x'.strtolower(trim($str));
139 $str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
140 return substr(str_replace(' ', '', $str), 1);
144 // --------------------------------------------------------------------
149 * Takes multiple words separated by spaces and underscores them
155 if ( ! function_exists('underscore'))
157 function underscore($str)
159 return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
163 // --------------------------------------------------------------------
168 * Takes multiple words separated by underscores and changes them to spaces
174 if ( ! function_exists('humanize'))
176 function humanize($str)
178 return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
183 /* End of file inflector_helper.php */
184 /* Location: ./system/helpers/inflector_helper.php */