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 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/trailing 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
// ------------------------------------------------------------------------
125
* Reduce Double Slashes
127
* Converts double slashes in a string to a single slash,
128
* except those found in http://
130
* http://www.some-site.com//index.php
134
* http://www.some-site.com/index.php
140
if ( ! function_exists('reduce_double_slashes'))
142
function reduce_double_slashes($str)
144
return preg_replace("#(^|[^:])//+#", "\\1/", $str);
148
// ------------------------------------------------------------------------
153
* Reduces multiple instances of a particular character. Example:
155
* Fred, Bill,, Joe, Jimmy
159
* Fred, Bill, Joe, Jimmy
163
* @param string the character you wish to reduce
164
* @param bool TRUE/FALSE - whether to trim the character from the beginning/end
167
if ( ! function_exists('reduce_multiples'))
169
function reduce_multiples($str, $character = ',', $trim = FALSE)
171
$str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
175
$str = trim($str, $character);
182
// ------------------------------------------------------------------------
185
* Create a Random String
187
* Useful for generating passwords or hashes.
190
* @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
191
* @param integer number of characters
194
if ( ! function_exists('random_string'))
196
function random_string($type = 'alnum', $len = 8)
200
case 'basic' : return mt_rand();
209
case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
211
case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
213
case 'numeric' : $pool = '0123456789';
215
case 'nozero' : $pool = '123456789';
220
for ($i=0; $i < $len; $i++)
222
$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
229
return md5(uniqid(mt_rand()));
234
$CI =& get_instance();
235
$CI->load->helper('security');
237
return do_hash(uniqid(mt_rand(), TRUE), 'sha1');
243
// ------------------------------------------------------------------------
246
* Add's _1 to a string or increment the ending number to allow _2, _3, etc
248
* @param string $str required
249
* @param string $separator What should the duplicate number be appended with
250
* @param string $first Which number should be used for the first dupe increment
253
function increment_string($str, $separator = '_', $first = 1)
255
preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
257
return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first;
260
// ------------------------------------------------------------------------
265
* Allows strings to be alternated. See docs...
268
* @param string (as many parameters as needed)
271
if ( ! function_exists('alternator'))
273
function alternator()
277
if (func_num_args() == 0)
282
$args = func_get_args();
283
return $args[($i++ % count($args))];
287
// ------------------------------------------------------------------------
294
* @param integer number of repeats
297
if ( ! function_exists('repeater'))
299
function repeater($data, $num = 1)
301
return (($num > 0) ? str_repeat($data, $num) : '');
306
/* End of file string_helper.php */
307
/* Location: ./system/helpers/string_helper.php */
b'\\ No newline at end of file'