summaryrefslogtreecommitdiffstats
path: root/system/helpers/string_helper.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-01-07 00:28:07 +0100
committerAndrey Andreev <narf@bofh.bg>2012-01-07 00:28:07 +0100
commit4921fed6c17a54efd4fac0bed4d058463bd9b601 (patch)
tree699ec1809e19e9ba6d6dba22cde4a33d56779c9f /system/helpers/string_helper.php
parent9252d7bf2208d351aad4292cb79c509391f0313f (diff)
Improve the smiley, string & text helpers
Diffstat (limited to 'system/helpers/string_helper.php')
-rw-r--r--system/helpers/string_helper.php81
1 files changed, 31 insertions, 50 deletions
diff --git a/system/helpers/string_helper.php b/system/helpers/string_helper.php
index 04d51c2f9..654f721b0 100644
--- a/system/helpers/string_helper.php
+++ b/system/helpers/string_helper.php
@@ -1,13 +1,13 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* NOTICE OF LICENSE
- *
+ *
* Licensed under the Open Software License version 3.0
- *
+ *
* This source file is subject to the Open Software License (OSL 3.0) that is
* bundled with this package in the files license.txt / license.rst. It is
* also available through the world wide web at this URL:
@@ -86,7 +86,7 @@ if ( ! function_exists('strip_slashes'))
}
else
{
- $str = stripslashes($str);
+ return stripslashes($str);
}
return $str;
@@ -182,12 +182,7 @@ if ( ! function_exists('reduce_multiples'))
{
$str = preg_replace('#'.preg_quote($character, '#').'{2,}#', $character, $str);
- if ($trim === TRUE)
- {
- $str = trim($str, $character);
- }
-
- return $str;
+ return ($trim === TRUE) ? trim($str, $character) : $str;
}
}
@@ -207,44 +202,32 @@ if ( ! function_exists('random_string'))
{
function random_string($type = 'alnum', $len = 8)
{
- switch($type)
+ 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';
- break;
- case 'nozero' : $pool = '123456789';
- break;
- }
-
- $str = substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len);
-
- return $str;
- 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;
+ case 'basic': return mt_rand();
+ case 'alnum':
+ case 'numeric':
+ case 'nozero':
+ case 'alpha':
+ switch ($type)
+ {
+ case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ break;
+ case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ break;
+ case 'numeric': $pool = '0123456789';
+ break;
+ case 'nozero': $pool = '123456789';
+ break;
+ }
+ return substr(str_shuffle(str_repeat($pool, ceil($len/strlen($pool)))),0,$len);
+ case 'unique':
+ case 'md5': return md5(uniqid(mt_rand()));
+ case 'encrypt':
+ case 'sha1':
+ $CI =& get_instance();
+ $CI->load->helper('security');
+ return do_hash(uniqid(mt_rand(), TRUE), 'sha1');
}
}
}
@@ -262,7 +245,6 @@ if ( ! function_exists('random_string'))
function increment_string($str, $separator = '_', $first = 1)
{
preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
-
return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first;
}
@@ -311,6 +293,5 @@ if ( ! function_exists('repeater'))
}
}
-
/* End of file string_helper.php */
-/* Location: ./system/helpers/string_helper.php */ \ No newline at end of file
+/* Location: ./system/helpers/string_helper.php */