This class is developed because PHP sometimes is very confusing in parameters and calling conventions.
You don't need to create objects of this class directly, rather use br()
magic function. For example:
$s = br('Some string');
In most cases you don't even need BrString itself but need it's great functions. For example:
echo(br('Some string')->trim()); if (br($fileName)->like('%txt')) { echo('Text file'); } if (br($fileName)->match('|txt$|')) { echo('Also text file'); } echo(br('Some string')->indexOf('ome'));
Method/property | Description |
---|---|
like($pattern) | Check string against syntax of SQL command LIKE |
inArray($array) | Find string in array |
trim($charlist = " \t\n\r\0\x0B") | Trim empty spaces from beginning and end of the string |
trimLeft($charlist = " \t\n\r\0\x0B") | Trim empty spaces from beginning of the string |
trimRight($charlist = " \t\n\r\0\x0B") | Trim empty spaces from end of the string |
length() | Return string length |
toLowerCase() | Convert string to lower case |
toUpperCase() | Convert string to upper case |
substring($start = 0, $length = 0xFFFFFFF) | Return substring of the string |
replace/replaceIgnoreCase($search, $replace, &$count = NULL) | Replace string occurance |
replaceRegExp($pattern, $replacement , $limit = -1, &$count = NULL) | Replace string occurance using regular expression |
match/matchAll($pattern, &$matches = NULL, $flags = 0, $offset = 0) | Match regular expression |
charAt($index) | Return chart at $index position |
indexOf($search) | Return index of substring if it's exists |
subst($patern, ...array of values...) | Substitute placholders with values. For example:
$sql = br('SELECT * FROM table WHERE id = ?')->subst(1); echo($sql); // SELECT * FROM table WHERE id = 1 |
split($delimiters = ',;') | Convert string to array. |