Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
| 8 | * @author Rick Ellis
|
| 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
| 10 | * @license http://www.codeignitor.com/user_guide/license.html
|
| 11 | * @link http://www.codeigniter.com
|
| 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * CodeIgniter Inflector Helpers
|
| 20 | *
|
| 21 | * @package CodeIgniter
|
| 22 | * @subpackage Helpers
|
| 23 | * @category Helpers
|
| 24 | * @author Rick Ellis
|
| 25 | * @link http://www.codeigniter.com/user_guide/helpers/directory_helper.html
|
| 26 | */
|
| 27 |
|
| 28 |
|
| 29 | // --------------------------------------------------------------------
|
| 30 |
|
| 31 | /**
|
| 32 | * Singular
|
| 33 | *
|
| 34 | * Takes a singular word and makes it plural
|
| 35 | *
|
| 36 | * @access public
|
| 37 | * @param string
|
| 38 | * @return str
|
| 39 | */
|
| 40 | function singular($str)
|
| 41 | {
|
| 42 | $str = strtolower(trim($str));
|
| 43 | $end = substr($str, -3);
|
| 44 |
|
| 45 | if ($end == 'ies')
|
| 46 | {
|
| 47 | $str = substr($str, 0, strlen($str)-3).'y';
|
| 48 | }
|
| 49 | else
|
| 50 | {
|
| 51 | $end = substr($str, -1);
|
| 52 |
|
| 53 | if ($end == 's')
|
| 54 | {
|
| 55 | $str = substr($str, 0, strlen($str)-1);
|
| 56 | }
|
| 57 | }
|
| 58 |
|
| 59 | return $str;
|
| 60 | }
|
| 61 |
|
| 62 | // --------------------------------------------------------------------
|
| 63 |
|
| 64 | /**
|
| 65 | * Plural
|
| 66 | *
|
| 67 | * Takes a plural word and makes it singular
|
| 68 | *
|
| 69 | * @access public
|
| 70 | * @param string
|
| 71 | * @return str
|
| 72 | */
|
| 73 | function plural($str)
|
| 74 | {
|
| 75 | $str = strtolower(trim($str));
|
| 76 | $end = substr($str, -1);
|
| 77 |
|
| 78 | if ($end == 'y')
|
| 79 | {
|
| 80 | $str = substr($str, 0, strlen($str)-1).'ies';
|
| 81 | }
|
| 82 | elseif ($end != 's')
|
| 83 | {
|
| 84 | $str .= 's';
|
| 85 | }
|
| 86 |
|
| 87 | return $str;
|
| 88 | }
|
| 89 |
|
| 90 | // --------------------------------------------------------------------
|
| 91 |
|
| 92 | /**
|
| 93 | * Camelize
|
| 94 | *
|
| 95 | * Takes multiple words separated by spaces or underscores and camelizes them
|
| 96 | *
|
| 97 | * @access public
|
| 98 | * @param string
|
| 99 | * @return str
|
| 100 | */
|
| 101 | function camelize($str)
|
| 102 | {
|
| 103 | $str = 'x'.strtolower(trim($str));
|
| 104 | $str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
|
| 105 | return substr(str_replace(' ', '', $str), 1);
|
| 106 | }
|
| 107 |
|
| 108 | // --------------------------------------------------------------------
|
| 109 |
|
| 110 | /**
|
| 111 | * Underscore
|
| 112 | *
|
| 113 | * Takes multiple words separated by spaces and underscores them
|
| 114 | *
|
| 115 | * @access public
|
| 116 | * @param string
|
| 117 | * @return str
|
| 118 | */
|
| 119 | function underscore($str)
|
| 120 | {
|
| 121 | return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
|
| 122 | }
|
| 123 |
|
| 124 | // --------------------------------------------------------------------
|
| 125 |
|
| 126 | /**
|
| 127 | * Humanize
|
| 128 | *
|
| 129 | * Takes multiple words separated by underscores and changes them to spaces
|
| 130 | *
|
| 131 | * @access public
|
| 132 | * @param string
|
| 133 | * @return str
|
| 134 | */
|
| 135 | function humanize($str)
|
| 136 | {
|
| 137 | return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
|
| 138 | }
|
| 139 |
|
admin | 5b179b5 | 2006-09-20 23:44:53 +0000 | [diff] [blame] | 140 | ?> |