inflector_helper.php
Go to the documentation of this file.00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 if ( ! function_exists('singular'))
00041 {
00042 function singular($str)
00043 {
00044 $str = strtolower(trim($str));
00045 $end = substr($str, -3);
00046
00047 if ($end == 'ies')
00048 {
00049 $str = substr($str, 0, strlen($str)-3).'y';
00050 }
00051 elseif ($end == 'ses')
00052 {
00053 $str = substr($str, 0, strlen($str)-2);
00054 }
00055 else
00056 {
00057 $end = substr($str, -1);
00058
00059 if ($end == 's')
00060 {
00061 $str = substr($str, 0, strlen($str)-1);
00062 }
00063 }
00064
00065 return $str;
00066 }
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 if ( ! function_exists('plural'))
00082 {
00083 function plural($str, $force = FALSE)
00084 {
00085 $str = strtolower(trim($str));
00086 $end = substr($str, -1);
00087
00088 if ($end == 'y')
00089 {
00090 $str = substr($str, 0, strlen($str)-1).'ies';
00091 }
00092 elseif ($end == 's')
00093 {
00094 if ($force == TRUE)
00095 {
00096 $str .= 'es';
00097 }
00098 }
00099 else
00100 {
00101 $str .= 's';
00102 }
00103
00104 return $str;
00105 }
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 if ( ! function_exists('camelize'))
00120 {
00121 function camelize($str)
00122 {
00123 $str = 'x'.strtolower(trim($str));
00124 $str = ucwords(preg_replace('/[\s_]+/', ' ', $str));
00125 return substr(str_replace(' ', '', $str), 1);
00126 }
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 if ( ! function_exists('underscore'))
00141 {
00142 function underscore($str)
00143 {
00144 return preg_replace('/[\s]+/', '_', strtolower(trim($str)));
00145 }
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 if ( ! function_exists('humanize'))
00160 {
00161 function humanize($str)
00162 {
00163 return ucwords(preg_replace('/[_]+/', ' ', strtolower(trim($str))));
00164 }
00165 }
00166
00167
00168
00169