summaryrefslogtreecommitdiffstats
path: root/system/helpers/string_helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/helpers/string_helper.php')
-rwxr-xr-x[-rw-r--r--]system/helpers/string_helper.php73
1 files changed, 45 insertions, 28 deletions
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index c0409dc5a..7765bba31 100644..100755
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -30,7 +30,7 @@
/**
* Trim Slashes
*
- * Removes any leading/traling slashes from a string:
+ * Removes any leading/trailing slashes from a string:
*
* /this/that/theother/
*
@@ -41,15 +41,15 @@
* @access public
* @param string
* @return string
- */
+ */
if ( ! function_exists('trim_slashes'))
{
function trim_slashes($str)
{
return trim($str, '/');
- }
+ }
}
-
+
// ------------------------------------------------------------------------
/**
@@ -60,13 +60,13 @@ if ( ! function_exists('trim_slashes'))
* @access public
* @param mixed string or array
* @return mixed string or array
- */
+ */
if ( ! function_exists('strip_slashes'))
{
function strip_slashes($str)
{
if (is_array($str))
- {
+ {
foreach ($str as $key => $val)
{
$str[$key] = strip_slashes($val);
@@ -76,7 +76,7 @@ if ( ! function_exists('strip_slashes'))
{
$str = stripslashes($str);
}
-
+
return $str;
}
}
@@ -91,7 +91,7 @@ if ( ! function_exists('strip_slashes'))
* @access public
* @param string
* @return string
- */
+ */
if ( ! function_exists('strip_quotes'))
{
function strip_quotes($str)
@@ -110,16 +110,17 @@ if ( ! function_exists('strip_quotes'))
* @access public
* @param string
* @return string
- */
+ */
if ( ! function_exists('quotes_to_entities'))
{
function quotes_to_entities($str)
- {
+ {
return str_replace(array("\'","\"","'",'"'), array("'",""","'","""), $str);
}
}
// ------------------------------------------------------------------------
+
/**
* Reduce Double Slashes
*
@@ -135,15 +136,15 @@ if ( ! function_exists('quotes_to_entities'))
* @access public
* @param string
* @return string
- */
+ */
if ( ! function_exists('reduce_double_slashes'))
{
function reduce_double_slashes($str)
{
- return preg_replace("#([^:])//+#", "\\1/", $str);
+ return preg_replace("#(^|[^:])//+#", "\\1/", $str);
}
}
-
+
// ------------------------------------------------------------------------
/**
@@ -162,7 +163,7 @@ if ( ! function_exists('reduce_double_slashes'))
* @param string the character you wish to reduce
* @param bool TRUE/FALSE - whether to trim the character from the beginning/end
* @return string
- */
+ */
if ( ! function_exists('reduce_multiples'))
{
function reduce_multiples($str, $character = ',', $trim = FALSE)
@@ -177,7 +178,7 @@ if ( ! function_exists('reduce_multiples'))
return $str;
}
}
-
+
// ------------------------------------------------------------------------
/**
@@ -186,22 +187,27 @@ if ( ! function_exists('reduce_multiples'))
* Useful for generating passwords or hashes.
*
* @access public
- * @param string type of random string. Options: alunum, numeric, nozero, unique
+ * @param string type of random string. basic, alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
* @param integer number of characters
* @return string
*/
if ( ! function_exists('random_string'))
-{
+{
function random_string($type = 'alnum', $len = 8)
- {
+ {
switch($type)
{
+ case 'basic' : return mt_rand();
+ break;
case 'alnum' :
case 'numeric' :
case 'nozero' :
-
+ case 'alpha' :
+
switch ($type)
{
+ case 'alpha' : $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ break;
case 'alnum' : $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'numeric' : $pool = '0123456789';
@@ -216,9 +222,20 @@ if ( ! function_exists('random_string'))
$str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
return $str;
- break;
- case 'unique' : return md5(uniqid(mt_rand()));
- break;
+ break;
+ case 'unique' :
+ case 'md5' :
+
+ return md5(uniqid(mt_rand()));
+ break;
+ case 'encrypt' :
+ case 'sha1' :
+
+ $CI =& get_instance();
+ $CI->load->helper('security');
+
+ return do_hash(uniqid(mt_rand(), TRUE), 'sha1');
+ break;
}
}
}
@@ -233,12 +250,12 @@ if ( ! function_exists('random_string'))
* @access public
* @param string (as many parameters as needed)
* @return string
- */
+ */
if ( ! function_exists('alternator'))
{
function alternator()
{
- static $i;
+ static $i;
if (func_num_args() == 0)
{
@@ -259,13 +276,13 @@ if ( ! function_exists('alternator'))
* @param string
* @param integer number of repeats
* @return string
- */
+ */
if ( ! function_exists('repeater'))
{
function repeater($data, $num = 1)
{
return (($num > 0) ? str_repeat($data, $num) : '');
- }
+ }
}