summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide_src/source')
-rw-r--r--user_guide_src/source/helpers/string_helper.rst103
-rw-r--r--user_guide_src/source/helpers/text_helper.rst138
-rw-r--r--user_guide_src/source/helpers/typography_helper.rst45
3 files changed, 196 insertions, 90 deletions
diff --git a/user_guide_src/source/helpers/string_helper.rst b/user_guide_src/source/helpers/string_helper.rst
index 86b1cdb34..1c2404400 100644
--- a/user_guide_src/source/helpers/string_helper.rst
+++ b/user_guide_src/source/helpers/string_helper.rst
@@ -19,39 +19,53 @@ The following functions are available:
random_string()
===============
+.. php:function:: random_string($type = 'alnum', $len = 8)
+
+ :param string $type: Randomization type
+ :param int $len: Output string length
+ :returns: string
+
Generates a random string based on the type and length you specify.
Useful for creating passwords or generating random hashes.
The first parameter specifies the type of string, the second parameter
specifies the length. The following choices are available:
-alpha, alunum, numeric, nozero, unique, md5, encrypt and sha1
+alpha, alunum, basic, numeric, nozero, md5 and sha1
- **alpha**: A string with lower and uppercase letters only.
- **alnum**: Alpha-numeric string with lower and uppercase characters.
+- **basic**: A random number based on ``mt_rand()``.
- **numeric**: Numeric string.
- **nozero**: Numeric string with no zeros.
- **unique**: Encrypted with MD5 and uniqid(). Note: The length
parameter is not available for this type. Returns a fixed length 32
character string.
+- **md5**: An encrypted random number based on ``md5()``.
- **sha1**: An encrypted random number based on ``sha1()``.
-Usage example
-
-::
+Usage example::
echo random_string('alnum', 16);
+.. note:: Usage of the *unique* and *encrypt* types is DEPRECATED. They
+ are just aliases for *md5* and *sha1* respectively.
+
increment_string()
==================
+.. php:function:: increment_string($str, $separator = '_', $first = 1)
+
+ :param string $str: Input string
+ :param string $separator: Separator to append a duplicate number with
+ :param int $first: Starting number
+ :returns: string
+
Increments a string by appending a number to it or increasing the
number. Useful for creating "copies" or a file or duplicating database
content which has unique titles or slugs.
-Usage example
-
-::
+Usage example::
echo increment_string('file', '_'); // "file_1"
echo increment_string('file', '-', 2); // "file-2"
@@ -60,10 +74,13 @@ Usage example
alternator()
============
-Allows two or more items to be alternated between, when cycling through
-a loop. Example
+.. php:function:: alternator($args)
-::
+ :param mixed $args: A variable number of arguments
+ :returns: mixed
+
+Allows two or more items to be alternated between, when cycling through
+a loop. Example::
for ($i = 0; $i < 10; $i++)
{     
@@ -105,10 +122,15 @@ The above would generate 30 newlines.
reduce_double_slashes()
=======================
+.. php:function:: reduce_double_slashes($str)
+
+ :param string $str: Input string
+ :returns: string
+
Converts double slashes in a string to a single slash, except those
-found in http://. Example
+found in URL protocol prefixes (e.g. http://).
-::
+Example::
$string = "http://example.com//index.php";
echo reduce_double_slashes($string); // results in "http://example.com/index.php"
@@ -116,16 +138,14 @@ found in http://. Example
strip_slashes()
===============
-Removes any slashes from a string. Example
+.. php:function:: strip_slashes($data)
-::
-
- $str = "Is your name O\'reilly?";
- echo strip_slashes($str); // results in Is your name O'reilly?
+ :param array $data: Input
+ :returns: array
-You can also use an array. Example
+Removes any slashes from an array of strings.
-::
+Example::
$str = array(
'question'  => 'Is your name O\'reilly?',
@@ -134,15 +154,17 @@ You can also use an array. Example
$str = strip_slashes($str);
-The above will return the following array:
-
-::
+The above will return the following array::
array(
'question'  => "Is your name O'reilly?",
'answer' => "No, my name is O'connor."
);
+.. note:: For historical reasons, this function will also accept
+ and handle string inputs. This however makes it just an
+ alias for ``stripslashes()``.
+
trim_slashes()
==============
@@ -163,37 +185,35 @@ Removes any leading/trailing slashes from a string. Example::
reduce_multiples()
==================
+.. php:function:: reduce_multiples($str, $character = '', $trim = FALSE)
+
+ :param string $str: Text to search in
+ :param string $character: Character to reduce
+ :param bool $trim: Whether to also trim the specified character
+ :returns: string
+
Reduces multiple instances of a particular character occuring directly
after each other. Example::
$string = "Fred, Bill,, Joe, Jimmy";
$string = reduce_multiples($string,","); //results in "Fred, Bill, Joe, Jimmy"
-The function accepts the following parameters:
-
-::
-
- reduce_multiples(string: text to search in, string: character to reduce, boolean: whether to remove the character from the front and end of the string)
-
-The first parameter contains the string in which you want to reduce the
-multiplies. The second parameter contains the character you want to have
-reduced. The third parameter is FALSE by default; if set to TRUE it will
-remove occurences of the character at the beginning and the end of the
-string. Example:
-
-::
+If the third parameter is set to TRUE it will remove occurences of the
+character at the beginning and the end of the string. Example::
$string = ",Fred, Bill,, Joe, Jimmy,";
$string = reduce_multiples($string, ", ", TRUE); //results in "Fred, Bill, Joe, Jimmy"
-
quotes_to_entities()
====================
-Converts single and double quotes in a string to the corresponding HTML
-entities. Example
+.. php:function:: quotes_to_entities($str)
-::
+ :param string $str: Input string
+ :returns: string
+
+Converts single and double quotes in a string to the corresponding HTML
+entities. Example::
$string = "Joe's \"dinner\"";
$string = quotes_to_entities($string); //results in "Joe&#39;s &quot;dinner&quot;"
@@ -201,6 +221,11 @@ entities. Example
strip_quotes()
==============
+.. php:function:: strip_quotes($str)
+
+ :param string $str: Input string
+ :returns: string
+
Removes single and double quotes from a string. Example::
$string = "Joe's \"dinner\"";
diff --git a/user_guide_src/source/helpers/text_helper.rst b/user_guide_src/source/helpers/text_helper.rst
index 8cb2d6f96..2b71432ef 100644
--- a/user_guide_src/source/helpers/text_helper.rst
+++ b/user_guide_src/source/helpers/text_helper.rst
@@ -10,9 +10,7 @@ text.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('text');
@@ -21,7 +19,14 @@ The following functions are available:
word_limiter()
==============
-Truncates a string to the number of **words** specified. Example::
+.. php:function:: word_limiter($str, $limit = 100, $end_char = '&#8230;')
+
+ :param string $str: Input string
+ :param int $limit: Limit
+ :param string $end_char: End character (usually an ellipsis)
+ :returns: string
+
+Truncates a string to the number of *words* specified. Example::
$string = "Here is a nice text string consisting of eleven words.";
$string = word_limiter($string, 4);
@@ -33,11 +38,18 @@ default it adds an ellipsis.
character_limiter()
===================
-Truncates a string to the number of **characters** specified. It
+.. php:function:: character_limiter($str, $n = 500, $end_char = '&#8230;')
+
+ :param string $str: Input string
+ :param int $n: Number of characters
+ :param string $end_char: End character (usually an ellipsis)
+ :returns: string
+
+Truncates a string to the number of *characters* specified. It
maintains the integrity of words so the character count may be slightly
-more or less then what you specify. Example
+more or less then what you specify.
-::
+Example::
$string = "Here is a nice text string consisting of eleven words.";
$string = character_limiter($string, 20);
@@ -46,55 +58,78 @@ more or less then what you specify. Example
The third parameter is an optional suffix added to the string, if
undeclared this helper uses an ellipsis.
-**Note:** If you need to truncate to an exact number of characters please see
-the :ref:`ellipsize` function below.
+.. note:: If you need to truncate to an exact number of characters please
+ see the :php:func:`ellipsize()` function below.
ascii_to_entities()
===================
+.. php:function:: ascii_to_entities($str)
+
+ :param string $str: Input string
+ :returns: string
+
Converts ASCII values to character entities, including high ASCII and MS
Word characters that can cause problems when used in a web page, so that
they can be shown consistently regardless of browser settings or stored
reliably in a database. There is some dependence on your server's
supported character sets, so it may not be 100% reliable in all cases,
but for the most part it should correctly identify characters outside
-the normal range (like accented characters). Example
+the normal range (like accented characters).
-::
+Example::
$string = ascii_to_entities($string);
entities_to_ascii()
===================
-This function does the opposite of the previous one; it turns character
-entities back into ASCII.
+.. php:function::entities_to_ascii($str, $all = TRUE)
+
+ :param string $str: Input string
+ :param bool $all: Whether to convert unsafe entities as well
+ :returns: string
+
+This function does the opposite of :php:func:`ascii_to_entities()`.
+It turns character entities back into ASCII.
convert_accented_characters()
=============================
-Transliterates high ASCII characters to low ASCII equivalents, useful
+.. php:function:: convert_accented_characters($str)
+
+ :param string $str: Input string
+ :returns: string
+
+Transliterates high ASCII characters to low ASCII equivalents. Useful
when non-English characters need to be used where only standard ASCII
characters are safely used, for instance, in URLs.
-::
+Example::
$string = convert_accented_characters($string);
-This function uses a companion config file
-`application/config/foreign_chars.php` to define the to and from array
-for transliteration.
+.. note:: This function uses a companion config file
+ `application/config/foreign_chars.php` to define the to and
+ from array for transliteration.
word_censor()
=============
+.. php:function:: word_censor($str, $censored, $replacement = '')
+
+ :param string $str: Input string
+ :param array $censored: List of bad words to censor
+ :param string $replacement: What to replace bad words with
+ :returns: string
+
Enables you to censor words within a text string. The first parameter
will contain the original string. The second will contain an array of
-words which you disallow. The third (optional) parameter can contain a
-replacement value for the words. If not specified they are replaced with
-pound signs: ####. Example
+words which you disallow. The third (optional) parameter can contain
+a replacement value for the words. If not specified they are replaced
+with pound signs: ####.
-::
+Example::
$disallowed = array('darn', 'shucks', 'golly', 'phooey');
$string = word_censor($string, $disallowed, 'Beep!');
@@ -102,48 +137,74 @@ pound signs: ####. Example
highlight_code()
================
+.. php:function:: highlight_code($str)
+
+ :param string $str: Input string
+ :returns: string
+
Colorizes a string of code (PHP, HTML, etc.). Example::
$string = highlight_code($string);
-The function uses PHP's highlight_string() function, so the colors used
-are the ones specified in your php.ini file.
+The function uses PHP's ``highlight_string()`` function, so the
+colors used are the ones specified in your php.ini file.
highlight_phrase()
==================
+.. php:function:: highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '</strong>')
+
+ :param string $str: Input string
+ :param string $phrase: Phrase to highlight
+ :param string $tag_open: Opening tag used for the highlight
+ :param string $tag_close: Closing tag for the highlight
+ :returns: string
+
Will highlight a phrase within a text string. The first parameter will
contain the original string, the second will contain the phrase you wish
to highlight. The third and fourth parameters will contain the
-opening/closing HTML tags you would like the phrase wrapped in. Example
+opening/closing HTML tags you would like the phrase wrapped in.
-::
+Example::
$string = "Here is a nice text string about nothing in particular.";
- $string = highlight_phrase($string, "nice text", '<span style="color:#990000">', '</span>');
+ echo highlight_phrase($string, "nice text", '<span style="color:#990000;">', '</span>');
-The above text returns:
+The above code prints::
-Here is a nice text string about nothing in particular.
+ Here is a <span style="color:#990000;">nice text</span> string about nothing in particular.
word_wrap()
===========
-Wraps text at the specified **character** count while maintaining
-complete words. Example
+.. php:function:: word_wrap($str, $charlim = 76)
+
+ :param string $str: Input string
+ :param int $charlim: Character limit
+ :returns: string
-::
+Wraps text at the specified *character* count while maintaining
+complete words.
+
+Example::
$string = "Here is a simple string of text that will help us demonstrate this function.";
echo word_wrap($string, 25);
// Would produce: Here is a simple string of text that will help us demonstrate this function
-.. _ellipsize:
-
ellipsize()
===========
+.. php:function:: ellipsize($str, $max_length, $position = 1, $ellipsis = '&hellip;')
+
+ :param string $str: Input string
+ :param int $max_length: String length limit
+ :param mixed $position: Position to split at
+ (int or float)
+ :param string $ellipsis: What to use as the ellipsis character
+ :returns: string
+
This function will strip tags from a string, split it at a defined
maximum length, and insert an ellipsis.
@@ -156,14 +217,11 @@ string, .5 in the middle, and 0 at the left.
An optional forth parameter is the kind of ellipsis. By default,
&hellip; will be inserted.
-::
+Example::
$str = 'this_string_is_entirely_too_long_and_might_break_my_design.jpg';
echo ellipsize($str, 32, .5);
-Produces:
-
-::
-
- this_string_is_e&hellip;ak_my_design.jpg
+Produces::
+ this_string_is_e&hellip;ak_my_design.jpg \ No newline at end of file
diff --git a/user_guide_src/source/helpers/typography_helper.rst b/user_guide_src/source/helpers/typography_helper.rst
index f3202603a..3c81687ac 100644
--- a/user_guide_src/source/helpers/typography_helper.rst
+++ b/user_guide_src/source/helpers/typography_helper.rst
@@ -10,9 +10,7 @@ in semantically relevant ways.
Loading this Helper
===================
-This helper is loaded using the following code
-
-::
+This helper is loaded using the following code::
$this->load->helper('typography');
@@ -21,9 +19,18 @@ The following functions are available:
auto_typography()
=================
+.. php:function:: auto_typography($str, $reduce_linebreaks = FALSE)
+
+ :param string $str: Input string
+ :param bool $reduce_linebreaks: Whether to reduce multiple instances of double newlines to two
+ :returns: string
+
Formats text so that it is semantically and typographically correct
-HTML. Please see the :doc:`Typography Class <../libraries/typography>`
-for more info.
+HTML.
+
+This function is an alias for ``CI_Typography::auto_typography``.
+For more info, please see the :doc:`Typography Library
+<../libraries/typography>` documentation.
Usage example::
@@ -31,18 +38,34 @@ Usage example::
.. note:: Typographic formatting can be processor intensive, particularly if
you have a lot of content being formatted. If you choose to use this
- function you may want to consider `caching </general/caching>` your pages.
+ function you may want to consider `caching <../general/caching>` your
+ pages.
nl2br_except_pre()
==================
-Converts newlines to <br /> tags unless they appear within <pre> tags.
-This function is identical to the native PHP nl2br() function, except
-that it ignores <pre> tags.
+.. php:function:: nl2br_except_pre($str)
-Usage example
+ :param string $str: Input string
+ :returns: string
-::
+Converts newlines to <br /> tags unless they appear within <pre> tags.
+This function is identical to the native PHP ``nl2br()`` function,
+except that it ignores <pre> tags.
+
+Usage example::
$string = nl2br_except_pre($string);
+entity_decode()
+===============
+
+.. php:function:: entity_decode($str, $charset = NULL)
+
+ :param string $str: Input string
+ :param string $charset: Character set
+ :returns: string
+
+This function is an alias for ``CI_Security::entity_decode()``.
+Fore more info, please see the :doc:`Security Library
+<../libraries/security>` documentation. \ No newline at end of file