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 ellipsize() function below.

ascii_to_entities($str)

Parameters:

$str (string) – Input string

Returns:

A string with ASCII values converted to entities

Return type:

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:

$string = ascii_to_entities($string);

convert_accented_characters($str)

Parameters:

$str (string) – Input string

Returns:

A string with accented characters converted

Return type:

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);

Note

This function uses a companion config file application/config/foreign_chars.php to define the to and from array for transliteration.

word_censor($str, $censored[, $replacement = ”])

Parameters:

$str (string) – Input string

$censored (array) – List of bad words to censor

$replacement (string) – What to replace bad words with

Returns:

Censored string

Return type:

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: ####.

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.

Here is a <span style="color:#990000;">nice text</span> string about nothing in particular.

Note

This function used to use the <strong> tag by default. Older browsers might not support the new HTML5 mark tag, so it is recommended that you insert the following CSS code into your stylesheet if you need to support such browsers:

mark {
background: #ff0;
color: #000;
};

word_wrap($str[, $charlim = 76])

Parameters:

$str (string) – Input string

$charlim (int) – Character limit

Returns:

Word-wrapped string

Return type:

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.

This function will strip tags from a string, split it at a defined maximum length, and insert an ellipsis.

The first parameter is the string to ellipsize, the second is the number of characters in the final string. The third parameter is where in the string the ellipsis should appear from 0 – 1, left to right. For example. a value of 1 will place the ellipsis at the right of the 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.