CodeIgniter v4.5 API

text_helper.php

This file is part of CodeIgniter 4 framework.

(c) CodeIgniter Foundation admin@codeigniter.com

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Table of Contents

Functions

word_limiter()  : string
Word Limiter
character_limiter()  : string
Character Limiter
ascii_to_entities()  : string
High ASCII to Entities
entities_to_ascii()  : string
Entities to ASCII
word_censor()  : string
Word Censoring Function
highlight_code()  : string
Code Highlighter
highlight_phrase()  : string
Phrase Highlighter
convert_accented_characters()  : string
Convert Accented Foreign Characters to ASCII
word_wrap()  : string
Word Wrap
ellipsize()  : string
Ellipsize String
strip_slashes()  : array<string|int, mixed>|string
Strip Slashes
strip_quotes()  : string
Strip Quotes
quotes_to_entities()  : string
Quotes to Entities
reduce_double_slashes()  : string
Reduce Double Slashes
reduce_multiples()  : string
Reduce Multiples
random_string()  : string
Create a Random String
increment_string()  : string
Add's _1 to a string or increment the ending number to allow _2, _3, etc
alternator()  : string
Alternator
excerpt()  : string
Excerpt.

Functions

word_limiter()

Word Limiter

word_limiter(string $str[, int $limit = 100 ][, string $endChar = '&#8230;' ]) : string

Limits a string to X number of words.

Parameters
$str : string
$limit : int = 100
$endChar : string = '&#8230;'

the end character. Usually an ellipsis

Return values
string

character_limiter()

Character Limiter

character_limiter(string $str[, int $n = 500 ][, string $endChar = '&#8230;' ]) : string

Limits the string based on the character count. Preserves complete words so the character count may not be exactly as specified.

Parameters
$str : string
$n : int = 500
$endChar : string = '&#8230;'

the end character. Usually an ellipsis

Return values
string

ascii_to_entities()

High ASCII to Entities

ascii_to_entities(string $str) : string

Converts high ASCII text and MS Word special characters to character entities

Parameters
$str : string
Return values
string

entities_to_ascii()

Entities to ASCII

entities_to_ascii(string $str[, bool $all = true ]) : string

Converts character entities back to ASCII

Parameters
$str : string
$all : bool = true
Return values
string

word_censor()

Word Censoring Function

word_censor(string $str, array<string|int, mixed> $censored[, string $replacement = '' ]) : string

Supply a string and an array of disallowed words and any matched words will be converted to #### or to the replacement word you've submitted.

Parameters
$str : string

the text string

$censored : array<string|int, mixed>

the array of censored words

$replacement : string = ''

the optional replacement value

Return values
string

highlight_code()

Code Highlighter

highlight_code(string $str) : string

Colorizes code strings

Parameters
$str : string

the text string

Return values
string

highlight_phrase()

Phrase Highlighter

highlight_phrase(string $str, string $phrase[, string $tagOpen = '<mark>' ][, string $tagClose = '</mark>' ]) : string

Highlights a phrase within a text string

Parameters
$str : string

the text string

$phrase : string

the phrase you'd like to highlight

$tagOpen : string = '<mark>'

the opening tag to precede the phrase with

$tagClose : string = '</mark>'

the closing tag to end the phrase with

Return values
string

convert_accented_characters()

Convert Accented Foreign Characters to ASCII

convert_accented_characters(string $str) : string
Parameters
$str : string

Input string

Return values
string

word_wrap()

Word Wrap

word_wrap(string $str[, int $charlim = 76 ]) : string

Wraps text at the specified character. Maintains the integrity of words. Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor will URLs.

Parameters
$str : string

the text string

$charlim : int = 76

= 76 the number of characters to wrap at

Return values
string

ellipsize()

Ellipsize String

ellipsize(string $str, int $maxLength[, float|int $position = 1 ][, string $ellipsis = '&hellip;' ]) : string

This function will strip tags from a string, split it at its max_length and ellipsize

Parameters
$str : string

String to ellipsize

$maxLength : int

Max length of string

$position : float|int = 1

int (1|0) or float, .5, .2, etc for position to split

$ellipsis : string = '&hellip;'

ellipsis ; Default '...'

Return values
string

Ellipsized string

strip_slashes()

Strip Slashes

strip_slashes(array<string|int, mixed>|string $str) : array<string|int, mixed>|string

Removes slashes contained in a string or in an array

Parameters
$str : array<string|int, mixed>|string

string or array

Return values
array<string|int, mixed>|string

string or array

strip_quotes()

Strip Quotes

strip_quotes(string $str) : string

Removes single and double quotes from a string

Parameters
$str : string
Return values
string

quotes_to_entities()

Quotes to Entities

quotes_to_entities(string $str) : string

Converts single and double quotes to entities

Parameters
$str : string
Return values
string

reduce_double_slashes()

Reduce Double Slashes

reduce_double_slashes(string $str) : string

Converts double slashes in a string to a single slash, except those found in http://

http://www.some-site.com//index.php

becomes:

http://www.some-site.com/index.php

Parameters
$str : string
Return values
string

reduce_multiples()

Reduce Multiples

reduce_multiples(string $str[, string $character = ',' ][, bool $trim = false ]) : string

Reduces multiple instances of a particular character. Example:

Fred, Bill,, Joe, Jimmy

becomes:

Fred, Bill, Joe, Jimmy

Parameters
$str : string
$character : string = ','

the character you wish to reduce

$trim : bool = false

TRUE/FALSE - whether to trim the character from the beginning/end

Return values
string

random_string()

Create a Random String

The type 'basic', 'md5', and 'sha1' are deprecated. They are not cryptographically secure.

random_string([string $type = 'alnum' ][, int $len = 8 ]) : string

Useful for generating passwords or hashes.

Parameters
$type : string = 'alnum'

Type of random string. basic, alpha, alnum, numeric, nozero, md5, sha1, and crypto

$len : int = 8

Number of characters

Return values
string

increment_string()

Add's _1 to a string or increment the ending number to allow _2, _3, etc

increment_string(string $str[, string $separator = '_' ][, int $first = 1 ]) : string
Parameters
$str : string

Required

$separator : string = '_'

What should the duplicate number be appended with

$first : int = 1

Which number should be used for the first dupe increment

Return values
string

alternator()

Alternator

alternator(string ...$args) : string

Allows strings to be alternated. See docs...

Parameters
$args : string

(as many parameters as needed)

Return values
string

excerpt()

Excerpt.

excerpt(string $text[, string $phrase = null ][, int $radius = 100 ][, string $ellipsis = '...' ]) : string

Allows to extract a piece of text surrounding a word or phrase.

Parameters
$text : string

String to search the phrase

$phrase : string = null

Phrase that will be searched for.

$radius : int = 100

The amount of characters returned around the phrase.

$ellipsis : string = '...'

Ending that will be appended

If no $phrase is passed, will generate an excerpt of $radius characters from the beginning of $text.

Return values
string

        
On this page

Search results