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 String Helpers
21 * @package CodeIgniter
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/helpers/string_helper.html
28 // ------------------------------------------------------------------------
33 * Removes any leading/traling slashes from a string:
35 * /this/that/theother/
45 if ( ! function_exists('trim_slashes'))
47 function trim_slashes($str)
49 return trim($str, '/');
53 // ------------------------------------------------------------------------
58 * Removes slashes contained in a string or in an array
61 * @param mixed string or array
62 * @return mixed string or array
64 if ( ! function_exists('strip_slashes'))
66 function strip_slashes($str)
70 foreach ($str as $key => $val)
72 $str[$key] = strip_slashes($val);
77 $str = stripslashes($str);
84 // ------------------------------------------------------------------------
89 * Removes single and double quotes from a string
95 if ( ! function_exists('strip_quotes'))
97 function strip_quotes($str)
99 return str_replace(array('"', "'"), '', $str);
103 // ------------------------------------------------------------------------
108 * Converts single and double quotes to entities
114 if ( ! function_exists('quotes_to_entities'))
116 function quotes_to_entities($str)
118 return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str);
122 // ------------------------------------------------------------------------
124 * Reduce Double Slashes
126 * Converts double slashes in a string to a single slash,
127 * except those found in http://
129 * http://www.some-site.com//index.php
133 * http://www.some-site.com/index.php
139 if ( ! function_exists('reduce_double_slashes'))
141 function reduce_double_slashes($str)
143 return preg_replace("#([^:])//+#", "\\1/", $str);
147 // ------------------------------------------------------------------------
152 * Reduces multiple instances of a particular character. Example:
154 * Fred, Bill,, Joe, Jimmy
158 * Fred, Bill, Joe, Jimmy
162 * @param string the character you wish to reduce
163 * @param bool TRUE/FALSE - whether to trim the character from the beginning/end
166 if ( ! function_exists('reduce_multiples'))
168 function reduce_multiples($str, $character = ',', $trim = FALSE)
170 $str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
174 $str = trim($str, $character);
181 // ------------------------------------------------------------------------
184 * Create a Random String
186 * Useful for generating passwords or hashes.
189 * @param string type of random string. Options: alunum, numeric, nozero, unique
190 * @param integer number of characters
193 if ( ! function_exists('random_string'))
195 function random_string($type = 'alnum', $len = 8)
205 case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
207 case 'numeric' : $pool = '0123456789';
209 case 'nozero' : $pool = '123456789';
214 for ($i=0; $i < $len; $i++)
216 $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
220 case 'unique' : return md5(uniqid(mt_rand()));
226 // ------------------------------------------------------------------------
231 * Allows strings to be alternated. See docs...
234 * @param string (as many parameters as needed)
237 if ( ! function_exists('alternator'))
239 function alternator()
243 if (func_num_args() == 0)
248 $args = func_get_args();
249 return $args[($i++ % count($args))];
253 // ------------------------------------------------------------------------
260 * @param integer number of repeats
263 if ( ! function_exists('repeater'))
265 function repeater($data, $num = 1)
267 return (($num > 0) ? str_repeat($data, $num) : '');
272 /* End of file string_helper.php */
273 /* Location: ./system/helpers/string_helper.php */