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 ($var)
 
static cropString ($text, $length=100, $suffix='…', $isHTML=true)
 
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)
 

Member Function Documentation

static getDump (   $var)
static

Get the dump of a variable as string.

Parameters
$varThe variable to dump.
Returns
String

Definition at line 25 of file StringUtil.php.

static cropString (   $text,
  $length = 100,
  $suffix = '…',
  $isHTML = true 
)
static

Truncate a string up to a number of characters while preserving whole words and HTML tags code based on: http://www.dzone.com/snippets/truncate-text-preserving-html.

Parameters
$textString to truncate.
$lengthLength of returned string, excluding suffix.
$suffixEnding to be appended to the trimmed string.
$isHTMLIf true, HTML tags would be handled correctly
Returns
String

Definition at line 42 of file StringUtil.php.

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 95 of file StringUtil.php.

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"..>, <input..src="xxx"..>, <form..action="xxx"..>, <link..href="xxx"..>, <script..src="xxx"..> and extracts xxx.

Definition at line 135 of file StringUtil.php.

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 173 of file StringUtil.php.

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 239 of file StringUtil.php.

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 263 of file StringUtil.php.

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 282 of file StringUtil.php.

static removeTrailingComma (   $string)
static

Remove a trailing comma, if existing.

Parameters
$stringThe string to crop
Returns
The string

Definition at line 294 of file StringUtil.php.

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 303 of file StringUtil.php.

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 317 of file StringUtil.php.