From 442682e488181a9e9139f02bb657e501eb78573d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 22:52:12 +0200 Subject: Polish docs for String, Text and Typography helpers --- user_guide_src/source/helpers/string_helper.rst | 103 +++++++++++++++--------- 1 file changed, 64 insertions(+), 39 deletions(-) (limited to 'user_guide_src/source/helpers/string_helper.rst') 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's "dinner"" @@ -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\""; -- cgit v1.2.3-24-g4f1b