word_limiter()
word_limiter(string $str, integer $limit = 100, string $end_char = '…') : string
Word Limiter
Limits a string to X number of words.
Parameters
| string | $str | |
| integer | $limit | |
| string | $end_char | the end character. Usually an ellipsis |
CodeIgniter
An open source application development framework for PHP
This content is released under the MIT License (MIT)
Copyright (c) 2014-2019 British Columbia Institute of Technology Copyright (c) 2019 CodeIgniter Foundation
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
character_limiter(string $str, integer $n = 500, string $end_char = '…') : string
Character Limiter
Limits the string based on the character count. Preserves complete words so the character count may not be exactly as specified.
| string | $str | |
| integer | $n | |
| string | $end_char | the end character. Usually an ellipsis |
word_censor(string $str, array $censored, string $replacement = '') : string
Word Censoring Function
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.
| string | $str | the text string |
| array | $censored | the array of censored words |
| string | $replacement | the optional replacement value |
highlight_phrase(string $str, string $phrase, string $tag_open = '<mark>', string $tag_close = '</mark>') : string
Phrase Highlighter
Highlights a phrase within a text string
| string | $str | the text string |
| string | $phrase | the phrase you'd like to highlight |
| string | $tag_open | the opening tag to precede the phrase with |
| string | $tag_close | the closing tag to end the phrase with |
word_wrap(string $str, integer $charlim = 76) : string
Word Wrap
Wraps text at the specified character. Maintains the integrity of words. Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor will URLs.
| string | $str | the text string |
| integer | $charlim | = 76 the number of characters to wrap at |
ellipsize(string $str, integer $max_length, mixed $position = 1, string $ellipsis = '…') : string
Ellipsize String
This function will strip tags from a string, split it at its max_length and ellipsize
| string | $str | String to ellipsize |
| integer | $max_length | Max length of string |
| mixed | $position | int (1|0) or float, .5, .2, etc for position to split |
| string | $ellipsis | ellipsis ; Default '...' |
Ellipsized string
reduce_double_slashes(string $str) : string
Reduce Double Slashes
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
| string | $str |
reduce_multiples(string $str, string $character = ',', boolean $trim = false) : string
Reduce Multiples
Reduces multiple instances of a particular character. Example:
Fred, Bill,, Joe, Jimmy
becomes:
Fred, Bill, Joe, Jimmy
| string | $str | |
| string | $character | the character you wish to reduce |
| boolean | $trim | TRUE/FALSE - whether to trim the character from the beginning/end |
random_string(string $type = 'alnum', integer $len = 8) : string
Create a Random String
Useful for generating passwords or hashes.
| string | $type | Type of random string. basic, alpha, alnum, numeric, nozero, md5, sha1, and crypto |
| integer | $len | Number of characters |
increment_string(string $str, string $separator = '_', integer $first = 1) : string
Add's _1 to a string or increment the ending number to allow _2, _3, etc
| string | $str | Required |
| string | $separator | What should the duplicate number be appended with |
| integer | $first | Which number should be used for the first dupe increment |
excerpt(string $text, string $phrase = null, integer $radius = 100, string $ellipsis = '...') : string
Excerpt.
Allows to extract a piece of text surrounding a word or phrase.
| string | $text | String to search the phrase |
| string | $phrase | Phrase that will be searched for. |
| integer | $radius | The amount of characters returned around the phrase. |
| string | $ellipsis | Ending that will be appended |
If no $phrase is passed, will generate an excerpt of $radius characters from the beginning of $text.