Methods summary
public static
string
|
#
iReplaceOnce( string $find, string $replace, string $subject )
Replaces a string only once.
Replaces a string only once.
Caution: This function only takes strings as parameters, not arrays!
Parameters
- $find
string $find String to find
- $replace
string $replace String to replace
- $subject
string $subject String to process
Returns
string Processed string
|
public static
string
|
#
iReplaceOnceReverse( string $find, string $replace, string $subject )
Replaces a string only once, in reverse direction.
Replaces a string only once, in reverse direction.
Caution: This function only takes strings as parameters, not arrays!
Parameters
- $find
string $find String to find
- $replace
string $replace String to replace
- $subject
string $subject String to process
Returns
string Processed string
|
public static
integer
|
#
posReverse( string $haystack, string $needle, integer $start = 0 )
Finds a string position in reverse direction.
Finds a string position in reverse direction.
NOTE: The original cString::findLastPos-function of PHP4 only finds a single
character as needle.
Parameters
- $haystack
string $haystack String to search in
- $needle
string $needle String to search for
- $start
integer $start [optional] Offset
Returns
integer String position
|
public static
string|array
|
#
addSlashes( string|array $value )
Adds slashes to passed variable or array.
Adds slashes to passed variable or array.
Parameters
- $value
string|array $value Either a string or a multi-dimensional array of values
Returns
string|array
|
public static
string|array
|
#
stripSlashes( string|array $value )
Removes slashes from passed variable or array.
Removes slashes from passed variable or array.
Parameters
- $value
string|array $value Either a string or a multi-dimensional array of values
Returns
string|array
|
public static
boolean
|
#
endsWith( string $haystack, string $needle )
Checks if the string haystack ends with needle.
Checks if the string haystack ends with needle.
Parameters
- $haystack
string $haystack The string to check
- $needle
string $needle The string with which it should end
Returns
boolean
|
public static
boolean
|
#
contains( string $haystack, string $needle )
Returns true if needle can be found in haystack.
Returns true if needle can be found in haystack.
Parameters
- $haystack
string $haystack String to be searched
- $needle
string $needle String to search for
Returns
boolean
|
public static
string
|
#
strstr( string $haystack, string $needle, boolean $beforeNeedle = false )
Implementation of PHP 5.3's strstr with beforeNeedle.
Implementation of PHP 5.3's strstr with beforeNeedle.
Parameters
- $haystack
string $haystack String to be searched
- $needle
string $needle String to search for
- $beforeNeedle
boolean $beforeNeedle [optional] If true, return everything BEFORE needle
Returns
string
Link
|
public static
boolean
|
#
validateDateFormat( string $format )
This function checks if a given format is accepted by php's date
function.
This function checks if a given format is accepted by php's date
function.
Parameters
- $format
string $format format according to date function specification
Returns
boolean true if format is correct, false otherwise
|
public static
boolean
|
#
isUtf8( string $input )
Returns whether a string is UTF-8 encoded or not.
Returns whether a string is UTF-8 encoded or not.
Parameters
Returns
boolean
|
public static
boolean
|
#
isAlphanumeric( mixed $test, boolean $umlauts = true )
Checks if a value is alphanumeric.
Checks if a value is alphanumeric.
Parameters
- $test
mixed $test Value to test
- $umlauts
boolean $umlauts [optional] Use german umlauts
Returns
boolean Value is alphanumeric
|
public static
string
|
#
trimAfterWord( string $string, integer $maxlen )
Trims a string to a given length and makes sure that all words up to $maxlen
are preserved, without exceeding $maxlen.
Trims a string to a given length and makes sure that all words up to $maxlen
are preserved, without exceeding $maxlen.
Warning: Currently, this function uses a regular ASCII-Whitespace to do the
separation test. If you are using ' ' to create spaces, this function
will fail.
Example: $string = "This is a simple test"; echo
cString::trimAfterWord($string, 15);
This would output "This is a", since this function respects word boundaries
and doesn't operate beyond the limit given by $maxlen.
Parameters
- $string
string $string The string to operate on
- $maxlen
integer $maxlen The maximum number of characters
Returns
string The resulting string
|
public static
string
|
#
trimHard( string $string, integer $maxlen, string $fillup = '...' )
Trims a string to a specific length.
Trims a string to a specific length.
If the string is longer than $maxlen, dots are inserted ("...") right before
$maxlen.
Example: $string = "This is a simple test"; echo cString::trimHard ($string,
15);
This would output "This is a si...", since the string is longer than $maxlen
and the resulting string matches 15 characters including the dots.
Parameters
- $string
string $string The string to operate on
- $maxlen
integer $maxlen The maximum number of characters
- $fillup
string $fillup [optional]
Returns
string The resulting string
|
public static
string
|
#
trimSentence( string $string, integer $approxlen, boolean $hard = false )
Trims a string to a approximate length preserving sentence boundaries.
Trims a string to a approximate length preserving sentence boundaries.
The algorithm inside calculates the sentence length to the previous and next
sentences. The distance to the next sentence which is smaller will be taken to
trim the string to match the approximate length parameter.
Example:
$string = "This contains two sentences. "; $string .= "Lets play around with
them. ";
echo cString::trimSentence($string, 40); echo cString::trimSentence($string,
50);
The first example would only output the first sentence, the second example
both sentences.
Explanation:
To match the given max length closely, the function calculates the distance
to the next and previous sentences. Using the maxlength of 40 characters, the
distance to the previous sentence would be 8 characters, and to the next
sentence it would be 19 characters. Therefore, only the previous sentence is
displayed.
The second example displays the second sentence also, since the distance to
the next sentence is only 9 characters, but to the previous it is 18
characters.
If you specify the boolean flag "$hard", the limit parameter creates a hard
limit instead of calculating the distance.
This function ensures that at least one sentence is returned.
Parameters
- $string
string $string The string to operate on
- $approxlen
integer $approxlen The approximate number of characters
- $hard
boolean $hard [optional] If true, use a hard limit for the number of characters
Returns
string The resulting string
|
public static
string
|
#
replaceDiacritics( string $string, string $sourceEncoding = 'UTF-8', string $targetEncoding = 'UTF-8' )
Converts diactritics to english characters whenever possible.
Converts diactritics to english characters whenever possible.
For german umlauts, this function converts the umlauts to their ASCII
equivalents (e.g. รค => ae).
For more information about diacritics, refer to http://en.wikipedia.org/wiki/Diacritic
For other languages, the diacritic marks are removed, if possible.
Parameters
- $string
string $string The string to operate on
- $sourceEncoding
string $sourceEncoding [optional; default: UTF-8] The source encoding
- $targetEncoding
string $targetEncoding [optional; default: UTF-8] The target encoding
Returns
string The resulting string
Throws
|
public static
string
|
#
recodeString( string $string, string $sourceEncoding, string $targetEncoding )
Converts a string to another encoding.
Converts a string to another encoding.
This function tries to detect which function to use (either recode or
iconv).
If $sourceEncoding and $targetEncoding are the same, this function returns
immediately.
For more information about encodings, refer to http://en.wikipedia.org/wiki/Character_encoding
For more information about the supported encodings in recode, refer to http://www.delorie.com/gnu/docs/recode/recode_toc.html
Note: depending on whether recode or iconv is used, the supported charsets
differ. The following ones are commonly used and are most likely supported by
both converters:
- ISO-8859-1 to ISO-8859-15
- ASCII
- UTF-8
Parameters
- $string
string $string The string to operate on
- $sourceEncoding
string $sourceEncoding The source encoding
- $targetEncoding
string $targetEncoding The target encoding (if false, use source encoding)
Returns
string The resulting string
Throws
Todo
Check if the charset names are the same for both converters
Implement a converter and charset checker to ensure compilance.
|
public static
string
|
#
cleanURLCharacters( string $string, boolean $replace = false )
Removes or converts all "evil" URL characters.
Removes or converts all "evil" URL characters.
This function removes or converts all characters which can make an URL
invalid.
Clean characters include:
- All characters between 32 and 126 which are not alphanumeric and
aren't one of the following: _-.
Parameters
- $string
string $string The string to operate on
- $replace
boolean $replace [optional] If true, all "unclean" characters are replaced
Returns
string The resulting string
Throws
|
public static
string
|
#
normalizeLineEndings( string $string, string $lineEnding = "\n" )
Normalizes line endings in passed string.
Normalizes line endings in passed string.
Parameters
- $string
string $string
- $lineEnding
string $lineEnding [optional] Feasible values are "\n", "\r" or "\r\n"
Returns
string
|