Detailed Description

StringUtil provides support for string manipulation.

Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

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 getDump (   $variable,
  $strlen = 100,
  $width = 25,
  $depth = 10,
  $i = 0,
$objects = [] 
)
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
$variableVariable to dump.
$strlenMax length of characters of each string to display (full length is shown)
$widthMax number of elements of an array to display (full length is shown)
$depthMax number of levels of nested objects/array to display
Returns
String

Definition at line 29 of file StringUtil.php.

◆ cropString()

static cropString (   $text,
  $length = 100,
  $suffix = '…',
  $exact = false 
)
static

Truncate a string up to a number of characters while preserving whole words and HTML tags.

Based on https://stackoverflow.com/questions/16583676/shorten-text-without-splitting-words-or-breaking-html-tags#answer-16584383

Parameters
$textString to truncate.
$lengthLength of returned string (optional, default: 100)
$suffixEnding to be appended to the trimmed string (optional, default: …)
$exactBoolean 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 excerpt (   $string,
  $phrase,
  $radius = 100 
)
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 getUrls (   $string)
static

Extraxt urls from a string.

Parameters
$stringThe 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 quotesplit (   $string)
static

Split a quoted string code from: http://php3.de/manual/de/function.split.php.

$string = '"hello, world", "say \"hello\"", 123, unquotedtext';
$result = quotsplit($string);
// results in:
// ['hello, world'] [say "hello"] [123] [unquotedtext]
Parameters
$stringThe string to split
Returns
An array of strings

Definition at line 275 of file StringUtil.php.

◆ splitQuoted()

static splitQuoted (   $string,
  $delim = '/ /',
  $quoteChr = '"',
  $preserve = false 
)
static

Split string preserving quoted strings code based on: http://www.php.net/manual/en/function.explode.php#94024.

Parameters
$stringString to split
$delimRegexp to use in preg_split
$quoteChrQuote character
$preserveBoolean whether to preserve the quote character or not
Returns
Array

Definition at line 341 of file StringUtil.php.

◆ underScoreToCamelCase()

static underScoreToCamelCase (   $string,
  $firstLowerCase = false 
)
static

Convert a string in underscore notation to camel case notation.

Code from http://snipt.net/hongster/underscore-to-camelcase/

Parameters
$stringThe string to convert
$firstLowerCaseBoolean 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 escapeForRegex (   $string)
static

Escape characters of a string for use in a regular expression Code from http://php.net/manual/de/function.preg-replace.php.

Parameters
$stringThe string
Returns
The escaped string

Definition at line 384 of file StringUtil.php.

◆ removeTrailingComma()

static removeTrailingComma (   $string)
static

Remove a trailing comma, if existing.

Parameters
$stringThe string to crop
Returns
The string

Definition at line 396 of file StringUtil.php.

◆ getBoolean()

static getBoolean (   $string)
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 slug (   $string)
static

Converts all accent characters to ASCII characters.

Code from http://stackoverflow.com/questions/2103797/url-friendly-username-in-php/2103815#2103815

Parameters
$stringText that might have accent characters
Returns
string Filtered string with replaced "nice" characters.

Definition at line 419 of file StringUtil.php.

◆ guidv4()

static 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.