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