Summary
- File
- Package hierarchy Helper
- Class hierarchy \TextHelper
Text helper
Text helper
strprotect(string $var, boolean $html_protect = self::HTML_PROTECT, integer $addslashes = self::ADDSLASHES_FORCE) : string
Protects an input variable. Never trust user input!
string | $var | Variable to protect. |
boolean | $html_protect | HTML_PROTECT if you don't accept the HTML code (it will be transformed by the corresponding HTML entities and won't be considerer by the web browsers). |
integer | $addslashes | If you want to escape the quotes in the string, use ADDSLASHES_FORCE, if you don't want, use the ADDSLASHES_NONE constant. |
The protected string.
None found |
wordwrap_html(string $str, integer $lenght, string $cut_char = '<br />', boolean $cut = true) : string
Inserts a carriage return every $lenght characters. It's equivalent to wordwrap PHP function but it can deal with the HTML entities.
An entity is coded on several characters and the wordwrap function counts several characters for an entity whereas it represents only one character.
string | $str | The string to wrap. |
integer | $lenght | The number of characters you want in a line. |
string | $cut_char | The character to insert every $lenght characters. The default value is ' |
boolean | $cut | True if you accept that a word would be broken apart, false if you want to cut only on a blank character. |
The wrapped HTML string.
None found |
substr_html(string $str, integer $start, integer $end = '') : string
Cuts a string containing some HTML code which contains some HTML entities. The substr PHP function considers a HTML entity as several characters.
This function allows you to consider them as only one character.
string | $str | The string you want to cut. |
integer | $start | If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth. If start is negative, the returned string will start at the start 'th character from the end of string . If string is less than or equal to start characters long, FALSE will be returned. |
integer | $end | If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string ). |
The sub string.
None found |
cut_string(string $string, integer $length) : string
Cut string to the desired length, ending with the last full word.
string | $string | A PHP string to convert to cut |
integer | $length | The desired length |
The substring
None found |
to_js_string(string $string, string $add_quotes = true) : string
Exports a variable to be used in a javascript script.
string | $string | A PHP string to convert to a JS one |
string | $add_quotes | If true, returned string will be bounded by single quotes |
The js equivalent string
None found |
to_json_string(string $string, string $add_quotes = true) : string
Exports a variable to be used in a json javascript script.
string | $string | A PHP string to convert to a json one |
string | $add_quotes | If true, returned string will be bounded by double quotes |
The json equivalent string
None found |
htmlspecialchars( $string, $flags = null, $encoding = 'UTF-8', $double_encode = true)
$string | ||
$flags | ||
$encoding | ||
$double_encode |
None found |
htmlspecialchars_decode( $string, $flags = null)
$string | ||
$flags |
None found |
html_entity_decode( $string, $flags = null, $encoding = 'UTF-8')
$string | ||
$flags | ||
$encoding |
None found |
strtolower( $string)
$string |
None found |
strtoupper( $string)
$string |
None found |
lcfirst( $string)
$string |
None found |
ucfirst( $string)
$string |
None found |
strlen( $string)
$string |
None found |
strpos( $string, $substring, $offset = '')
$string | ||
$substring | ||
$offset |
None found |
stripos( $string, $substring, $offset = '')
$string | ||
$substring | ||
$offset |
None found |
substr( $string, $start, $length = '')
$string | ||
$start | ||
$length |
None found |
mb_substr( $string, $start, $length = '')
$string | ||
$start | ||
$length |
None found |
strrchr( $string, $needle)
$string | ||
$needle |
None found |
strripos( $string, $needle, $offset = '')
$string | ||
$needle | ||
$offset |
None found |
strrpos( $string, $needle, $offset = '')
$string | ||
$needle | ||
$offset |
None found |
strstr( $string, $needle, $before_needle = '')
$string | ||
$needle | ||
$before_needle |
None found |
substr_count( $string, $needle, $encoding = '')
$string | ||
$needle | ||
$encoding |
None found |
convert_case( $string, $mode, $encoding = '')
$string | ||
$mode | ||
$encoding |
None found |
serialize( $string)
$string |
None found |
serialize_base64( $string)
$string |
None found |
unserialize( $string)
$string |
None found |
mb_unserialize( $string)
$string |
None found |
check_nbr_links(string $contents, integer $max_nbr, boolean $has_html_links = false) : boolean
Checks if a string contains less than a defined number of links (used to prevent SPAM).
string | $contents | String in which you want to count the number of links |
integer | $max_nbr | Maximum number of links accepted. |
boolean | $has_html_links | true if the content is in HTML |
true if there are no too much links, false otherwise.
None found |
utf8_wordwrap(string $string, integer $width = 75, string $break = "\n", string $cut = true) : string
Wraps a UTF-8 string to a given number of characters
string | $string | the input string |
integer | $width | the column width |
string | $break | the line is broken using the optional break parameter |
string | $cut | not used for the moment |
the given string wrapped at the specified column
None found |
is_base64( $string)
$string |
None found |