Code Igniter User Guide Version 1.5.0b3


String Helper

The String Helper file contains functions that assist in working with strings.

Loading this Helper

This helper is loaded using the following code:

$this->load->helper('string');

The following functions are available:

random_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:

Usage example:

echo random_string('alnum', 16);

alternator()

Allows two or more items to be alternated between, when cycling through a loop. Example: for ($i = 0; $i < 10; $i++)
{
    echo alternator('string one', 'string two');
}

You can add as many parameters as you want, and with each each iteration of your loop the next item will be returned.

for ($i = 0; $i < 10; $i++)
{
    echo alternator('one', 'two', 'three', 'four', 'five');
}

Note: To use multiple separate calls to this function simply call the function with no arguments to re-initialize.

repeater()

Generates repeating copies of the data you submit. Example:

$string = "\n";
echo repeater($string, 30);

The above would generate 30 newlines.