Adds line numbers on a given text
static
string
addLineNumbers
( &$str, [int $start = 1], [int $indent = 3], [string $afterNumberChar = ':'], [string $glue = "\n"], string $str)
-
string
$str: Input text
-
int
$start: Start numeration
-
int
$indent: Start indentation
-
string
$afterNumberChar: Suffix for the line numbers
-
string
$glue: Line glue
-
&$str
Removes whitespace chars from left, right and inside a string
static
string
allTrim
(string $str)
-
string
$str: Input string
Converts a string to camel case format
static
string
camelize
(string $str)
-
string
$str: Input string
Capitalizes all words of a given string
static
string
capitalize
(string $str)
-
string
$str: Input string
Reads a char from a string
static
string
charAt
(string $str, int $index)
-
string
$str: Input string
-
int
$index: Char index
Appends a value in the end of a string
static
string
concat
(string $str, string $concat)
-
string
$str: Input string
-
string
$concat: Concat string
Counts characters of a given string
static
int
countChars
(string $str, [bool $includeSpaces = FALSE])
-
string
$str: Input string
-
bool
$includeSpaces: Consider whitespace chars when couting
Counts the number of paragraphs of a given text
static
int
countParagraphs
(string $str)
Counts the number of sentences of a given text
static
int
countSentences
(string $str)
Counts the number of words of a given text
static
int
countWords
(string $str)
Remove all chars in a string before a given token is found
/* prints "order by name" */
static
string
cutBefore
(string $string, string $token, [bool $caseSensitive = TRUE])
-
string
$string: Input string
-
string
$token: Token
-
bool
$caseSensitive: Case sensitive?
Removes all chars after the last ocurrence of $cutOff in $string
/* prints "select * from table" */
static
string
cutLastOcurrence
(string $string, string $cutOff, [bool $caseSensitive = TRUE])
-
string
$string: Input string
-
string
$cutOff: Token
-
bool
$caseSensitive: Case sensitive?
Decodes a given string
Supported encoding types: base64, utf8 and quoted-printable.
static
string
decode
(string $str, string $encodeType)
-
string
$str: Input string
-
string
$encodeType: Encoding type
Encodes a given string
The supported encoding types (and their parameters) are base64 (none), utf8 (none), 7bit (nl), 8bit (nl) and quoted-printable (charset).
Examples:
StringUtils::encode('quoted printable', 'quoted-printable', array('charset' =>
'utf-8'));
static
string
encode
(string $str, string $encodeType, [array $params = NULL])
-
string
$str: Input string
-
string
$encodeType: Encode type
-
array
$params: Encoding params
Checks if a given string ends with a given value
static
bool
endsWith
(string $str, string $slice, [bool $caseSensitive = TRUE], [bool $ignSpaces = TRUE])
-
string
$str: Input string
-
string
$slice: Comparison value
-
bool
$caseSensitive: Case sensitive?
-
bool
$ignSpaces: Ignore initial whitespace chars
Escapes a string according to a given pattern
Patterns:
- html: escapes HTML special chars
- htmlall: escapes HTML entities
- url: escapes URL special chars (using http://www.php.net/rawurlencode)
- quotes: escapes quotes
- javascript: escapes JS code
- mail: replaces '@' by 'at' and '.' by 'dot'
static
string
escape
(string $str, [string $escapeType = 'html'])
-
string
$str: Input string
-
string
$escapeType
Splits the string using $sep as separator
static
array
explode
(string $str, string $sep)
-
string
$str: Input string
-
string
$sep: Separator
Applies a given filter on a string
Filter types:
- alpha: removes all alpha chars
- alphalower : removes all lowercase alpha chars
- alphaupper : removes all uppercase alpha chars
- num : removes all numbers
- alphanum : removes all alphanumeric chars
- htmlentities : removes all html entities
- blank : removes all whitespace chars
static
string
filter
(string $str, [string $filterType = 'alphanum'], [string $replaceStr = ''])
-
string
$str: Input string
-
string
$filterType: Filter type
-
string
$replaceStr: Replacement string
Returns a fallback value when a given string is empty
static
string
ifEmpty
(string $str, string $replacement)
-
string
$str: Input string
-
string
$replacement: Fallback string
Implodes an array, returning the result as a string
static
string
implode
(array $values, string $glue)
-
array
$values: Input array
-
string
$glue: Glue
Indents a given text using $iChar as indent char
static
string
indent
(string $str, int $nChars, [string $iChar = ' '])
-
string
$str: Input string
-
int
$nChars: Number of times to repeat the indent char
-
string
$iChar: Indent char
Inserts a value in a given position of a string
static
string
insert
(string $str, [string $insValue = ''], [int $insPos = 0])
-
string
$str: Input string
-
string
$insValue: Insert value
-
int
$insPos: Insert position
Insert a char between every pair of chars of a string
static
string
insertChar
(string $str, [string $char = ' '], [bool $stripEmpty = TRUE])
-
string
$str: Input string
-
string
$char: Char to be inserted
-
bool
$stripEmpty: Strip whitespace chars
Checks if a string is composed only by lowercase chars
static
bool
isAllLower
(string $str)
-
string
$str: Input string
Checks if a string is composed only by uppercase chars
static
bool
isAllUpper
(string $str)
-
string
$str: Input string
Safely checks if a string is empty
A string will be considered empty when its length is 0 and a call to the empty() function returns TRUE.
static
bool
isEmpty
(string $str)
-
string
$str: Input string
Get $n chars from the left side of a string
static
string
left
(string $str, [int $n = 0])
-
string
$str: Input string
-
int
$n: Number of chars
This method has the functionality of an if-then-else statement
Given the function arguments, the method analyzes them in pairs, starting from the second (the first is the input string). For each pair A and B, if A is equal to the original string, B is returned. If none of the pairs matches, the last argument can be used as an "else".
Examples:
static
mixed
map
()
Checks if a value is present in a given string
static
bool
match
(string $str, string $search, [bool $caseSensitive = TRUE])
-
string
$str: Input string
-
string
$search: Search value
-
bool
$caseSensitive: Whether to do case sensitive search
Reads a portion of a string, start at $startAt
The start index is 1-based. Example:
$sb = new String Buffer('hello world');
/* prints "hello" */
static
string
mid
(string $str, [int $startAt = 1], [int $chars = 0])
-
string
$str: Input string
-
int
$startAt: Start index
-
int
$chars: Substring length
Normalizes a given string
Replaces all chars from positions 192-223 and 224-225 of the ASCII table by their 'normal' versions: áéíÁÈÒÖ by aeiAEOO.
static
string
normalize
(string $str)
-
string
$str: Input string
Generates a random string
static
string
randomString
(int $size, [bool $upper = TRUE], [bool $digit = TRUE])
-
int
$size: Desired string length
-
bool
$upper: Whether to use uppercase chars
-
bool
$digit: Whether to use digits
Performs a regular expression search and replace on a string
static
string
regexReplace
(string $str, string $pattern, string $replacement)
-
string
$str: Input string
-
string
$pattern: PCRE pattern
-
string
$replacement: Replacement
Replaces all occurrences of $from by $to in a given string
static
string
replace
(string $str, string $from, string $to)
-
string
$str: Input string
-
string
$from: Search
-
string
$to: Replace
Get $n chars from the right side of a string
static
string
right
(string $str, [int $n = 0])
-
string
$str: Input string
-
int
$n: Number of chars
Checks if a given string starts with a given value
static
bool
startsWith
(string $str, string $slice, [bool $caseSensitive = TRUE], [bool $ignSpaces = TRUE])
-
string
$str: Input string
-
string
$slice: Comparison value
-
bool
$caseSensitive: Case sensitive?
-
bool
$ignSpaces: Ignore initial whitespace chars
Replaces 2 or more whitespace chars in a string
static
string
stripBlank
(string $str, [string $replace = ' '])
-
string
$str: Input string
-
string
$replace: Replacement string
Surrounds a string with a prefix and a suffix
static
string
surround
(string $str, string $prefix, string $suffix)
-
string
$str: Input string
-
string
$prefix: Prefix
-
string
$suffix: Suffix
Truncate a given string to $length
If the length of the original string is lower than $length, the original string is returned.
static
string
truncate
(string $str, int $length, [int $truncSufix = '...'], [bool $forceBreak = TRUE])
-
string
$str: Input string
-
int
$length: New length
-
int
$truncSufix: Suffix to be appended in the end of the truncated string
-
bool
$forceBreak: Force break of long words
Adds or adjusts line breaks on a string, using $num chars per line
The $breakString parameter defines the character(s) to be used to represent a line break.
static
string
wrap
(string $str, int $num, [string $breakString = "\n"])
-
string
$str: Input string
-
int
$num: Chars per line
-
string
$breakString: Line break string
Adds line wraps on a given string
The number of chars per line is defined by the $num parameter. The $breakString parameter defines the character(s) to be used to represent a line break.
static
string
wrapLine
(string $str, int $num, [string $breakString = "\n"])
-
string
$str: Input string
-
int
$num: Chars per line
-
string
$breakString: Line break string
Inherited Methods
Inherited From PHP2Go
PHP2Go::PHP2Go()
PHP2Go::equals()
PHP2Go::generateUniqueId()
PHP2Go::getClassName()
PHP2Go::getConfigVal()
PHP2Go::getLangVal()
PHP2Go::getObjectName()
PHP2Go::getParentName()
PHP2Go::hasDestructor()
PHP2Go::hashCode()
PHP2Go::isA()
PHP2Go::isSubclassOf()
PHP2Go::logError()
PHP2Go::raiseError()
PHP2Go::registerDestructor()
PHP2Go::registerShutdownFunc()
PHP2Go::retrieve()
PHP2Go::store()
PHP2Go::__toString()