Detailed Description
StringUtil provides support for string manipulation.
Definition at line 18 of file StringUtil.php.
Static Public Member Functions | |
static | getDump ($variable, $strlen=100, $width=25, $depth=10, $i=0, &$objects=[]) |
static | cropString ($text, $length=100, $suffix='…', $exact=false) |
static | excerpt ($string, $phrase, $radius=100) |
static | getUrls ($string) |
static | quotesplit ($string) |
static | splitQuoted ($string, $delim='//', $quoteChr='"', $preserve=false) |
static | underScoreToCamelCase ($string, $firstLowerCase=false) |
static | escapeForRegex ($string) |
static | removeTrailingComma ($string) |
static | getBoolean ($string) |
static | slug ($string) |
static | guidv4 () |
Member Function Documentation
◆ getDump()
|
static |
Get the dump of a variable as string.
code from: https://www.leaseweb.com/labs/2013/10/smart-alternative-phps-var_dump-function/
- Parameters
-
$variable Variable to dump. $strlen Max length of characters of each string to display (full length is shown) $width Max number of elements of an array to display (full length is shown) $depth Max number of levels of nested objects/array to display
- Returns
- String
Definition at line 29 of file StringUtil.php.
◆ cropString()
|
static |
Truncate a string up to a number of characters while preserving whole words and HTML tags.
- Parameters
-
$text String to truncate. $length Length of returned string (optional, default: 100) $suffix Ending to be appended to the trimmed string (optional, default: …) $exact Boolean whether to allow to cut inside a word or not (optional, default: false)
- Returns
- String
Definition at line 137 of file StringUtil.php.
◆ excerpt()
|
static |
Create an excerpt from the given text around the given phrase code based on: http://stackoverflow.com/questions/1292121/how-to-generate-the-snippet-like-generated-by-google-with-php-and-mysql.
- Parameters
-
$string $phrase $radius
Definition at line 195 of file StringUtil.php.
◆ getUrls()
|
static |
Extraxt urls from a string.
- Parameters
-
$string The string to search in
- Returns
- An array with urls
- Note
- This method searches for occurences of <a..href="xxx"..>, <img..src="xxx"..>, <video..src="xxx"..>, <audio..src="xxx"..>, <input..src="xxx"..>, <form..action="xxx"..>, <link..href="xxx"..>, <script..src="xxx"..> and extracts xxx.
Definition at line 235 of file StringUtil.php.
◆ quotesplit()
|
static |
Split a quoted string code from: http://php3.de/manual/de/function.split.php.
- Parameters
-
$string The string to split
- Returns
- An array of strings
Definition at line 275 of file StringUtil.php.
◆ splitQuoted()
|
static |
Split string preserving quoted strings code based on: http://www.php.net/manual/en/function.explode.php#94024.
- Parameters
-
$string String to split $delim Regexp to use in preg_split $quoteChr Quote character $preserve Boolean whether to preserve the quote character or not
- Returns
- Array
Definition at line 341 of file StringUtil.php.
◆ underScoreToCamelCase()
|
static |
Convert a string in underscore notation to camel case notation.
Code from http://snipt.net/hongster/underscore-to-camelcase/
- Parameters
-
$string The string to convert $firstLowerCase Boolean whether the first character should be lowercase or not (default: false)
- Returns
- The converted string
Definition at line 365 of file StringUtil.php.
◆ escapeForRegex()
|
static |
Escape characters of a string for use in a regular expression Code from http://php.net/manual/de/function.preg-replace.php.
- Parameters
-
$string The string
- Returns
- The escaped string
Definition at line 384 of file StringUtil.php.
◆ removeTrailingComma()
|
static |
Remove a trailing comma, if existing.
- Parameters
-
$string The string to crop
- Returns
- The string
Definition at line 396 of file StringUtil.php.
◆ getBoolean()
|
static |
Get the boolean value of a string.
- Parameters
-
$string
- Returns
- Boolean or the string, if it does not represent a boolean.
Definition at line 405 of file StringUtil.php.
◆ slug()
|
static |
Converts all accent characters to ASCII characters.
Code from http://stackoverflow.com/questions/2103797/url-friendly-username-in-php/2103815#2103815
- Parameters
-
$string Text that might have accent characters
- Returns
- string Filtered string with replaced "nice" characters.
Definition at line 419 of file StringUtil.php.
◆ guidv4()
|
static |
Generate a v4 UUID Code from https://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid#15875555.
- Returns
- string
Definition at line 433 of file StringUtil.php.