$chars
$chars : \Malenki\Bah\A
A collection of Malenki\Bah\C objects.
Play with Strings!
You can check whether string start or end by given another string. This is as simple as that following example:
$s = new S('Hello!');
var_dump($s->startsWith('He')); // true
var_dump($s->endsWith('yo!')); // false
You can use either S::$void
or S::$empty
magic getters to check whether
the string is void or not. This returns boolean
:
$s = new S('');
var_dump($s->void); // true
var_dump($s->empty); // true
$s = new S('foo');
var_dump($s->void); // false
var_dump($s->empty); // false
$s = new S(' ');
var_dump($s->void); // false
var_dump($s->empty); // false
Some language use other direction while writting words. For example, in english, we write words form left to right (or LTR), and in arabic languages, or in hebrew, we write words from right to left (or RTL).
Sometimes, you can have text mixing both directions. So, \Malenki\Bah\S
class allow you to test directionality of the string using some magic
getters and their aliases, returning boolean
.
Let’s check whether the given string is LTR:
$s = new S('Ceci est du français tout à fait banal.');
var_dump($s->ltr);
var_dump($s->is_ltr);
var_dump($s->is_left_to_right);
var_dump($s->left_to_right)
All previous lines into code sample will return true
.
Now, let’s check whether the given string is RTL or not:
$s = new S('أبجد');
var_dump($s->rtl);
var_dump($s->is_rtl);
var_dump($s->is_right_to_left);
var_dump($s->right_to_left);
Again, all lines will produce true
.
Now, let’s see how to check whether string has both directions:
$s = new S('Ceci est du français contenant le mot arabe أبجد qui veut dire "abjad".');
var_dump($s->has_mixed_direction);
var_dump($s->mixed_direction);
var_dump($s->is_ltr_and_rtl);
var_dump($s->ltr_and_rtl);
var_dump($s->is_rtl_and_ltr);
var_dump($s->rtl_and_ltr);
All should be true
!
You can get counts of chars or of bytes contained into the string using 3 ways:
count()
function (\Malenki\Bah\S
implements \Countable
interface), returns number of characters as primitive integer valueS::$length
magic getter, returns number of characters as
\Malenki\Bah\N
objectS::$bytes
magic getter returns an \Malenki\Bah\A
object, so you
can get number of bytes using length magic getter call or this object or
calling count()
with this object as argument.Now, a little example:
$s = new S('Je suis écrit en français.');
// using count() function
var_dump(count($s->bytes));
var_dump(count($s));
//using objects
var_dump($s->bytes->length);
var_dump($s->length);
This previous code sample should produce following output:
int(28)
int(26)
class Malenki\Bah\N#35 (1) {
public $value =>
int(28)
}
class Malenki\Bah\N#114 (1) {
public $value =>
int(26)
}
Magic getters for \Malenki\Bah\S::$md5
and \Malenki\Bah\S::$sha1
are
available, and return another \Malenki\Bah\S
object.
$s = new S('Hello!');
print($s->md5); // '952d2c56d0485958336747bcdd98590d'
print($s->sha1); // '69342c5c39e5ae5f0077aecc32c0f81811fb8193'
You can get one or more characters using a method to take one character using its position or by calling magic getters to have a collection of characters.
So, to get one characters, you have the choice within 3 brother methods:
$s = new S('azerty');
echo $s->take(1); // 'z'
// or
echo $s->charAt(1);
// or
echo $s->at(1);
To get a collection of characters as \malenki\Bah\A
object, use following
magic getter:
$s = new S('azerty');
$s->chars; // collection of characters a, z, e, r, t, and y
You have many ways to get substrings, you can explode the string, take range of characters, take some part matching some regexp…
You have two different ways to explode your string into simple manner.
So, for each way, you get a \Malenki\Bah\A
object having many
\Malenki\Bah\S
objects.
Using a regular expression is easy, you have 3 brother methods to do that,
so, look this examples (using join()
method of \Malenki\Bah\A
returned
object as guest star):
$s = new S('1940-06-18 20:00:00');
echo $s->explode('/[\s:-]/')->join(', '); // '1940, 06, 18, 20, 00, 00'
// or
echo $s->split('/[\s:-]/')->join(', ');
// or
echo $s->cut('/[\s:-]/')->join(', ');
To split the string each N characters, use this:
$s = new S('abcdefghijklmnopqrstuvwxyz');
$s->chunk(2)->join(','); // 'ab,cd,ef,gh,ij,kl,mn,op,qr,st,uv,wx,yz'
You can extract substring by given start position and the length of the substring.
$s = new S('azerty');
echo $s->sub(1, 3); // 'zer'
Prepending or appending piece of string is as simple as this:
$s = new S('World');
echo $s->prepend('Hello ')->append('!');
// or
echo $s->prepend(new S('Hello '))->append(new S('!'));
You must get Hello World!
as resulting string.
You can insert inside the string other string.
To insert string, you must have the string or object having __toString()
method, and the position as integer (object or primitive type).
$s = new S('Hello!');
echo $s->insert(' World', 5); // print 'Hello World!'
// or
echo $s->insert(new S(' World'), 5);
// or
echo $s->insert(' World', new N(5));
// or
echo $s->insert(new S(' World'), new N(5));
You can repeat the string how many times you wish. You have just to call S::times()
method:
$s = new S('Hi!');
echo $s->append(' ')->times(3)->strip;
You should get Hi! Hi! Hi!
. Note I used some other features to add/remove spaces too.
You could add LF ("\n"
) or CR ("\r"
) or CRLF ("\r\n"
) quickly using magic getters… S::$n
and S::$r
and orthers…
$s = new S('Something');
echo $s->n; // print "Something\n"
echo $s->r; // print "Something\r"
echo $s->r->n; // print "Something\r\n"
echo $s->rn; // print "Something\r\n"
echo $s->eol; // print "Something\n" if PHP_EOL is '\n'
This shorthand can be called as method taking one boolean argument to place
new line character after (default, true
) or before the string (false
):
$s = new S('Something');
echo $s->n(); // print "Something\n"
echo $s->n(true); // print "Something\n"
echo $s->n(false); // print "\nSomething"
echo $s->r(); // print "Something\r"
echo $s->r(true); // print "Something\r"
echo $s->r(false); // print "\rSomething"
To concatenate strings and/or objects having __toString()
method, then use
static method S::concat()
. This method takes any number of arguments and
returns \Malenki\Bah\S
object.
echo S::concat('Ceci est', new S(' une '), ' chaîne');
// print 'Ceci est une chaîne'
echo S::concat('Ceci est', new S(' une '), ' chaîne')->upper;
// print 'CECI EST UNE CHAÎNE'
Soon…
Some features are dédicated to removing part of the string, but more advanced removal can be performed using Regexp features, so, read chapter about Regexp too!
You can strip left and right sides (S::strip
), just left side
(S::lstrip
) or just right side (S::rstrip
).
You can strip string either by using methods or by using magic getters.
By using methods, you can change default character to strip. If you use
magic getter or methods without arguments, then stripping feature removes
only white space. To remove other characters, you must provide them using
array, string, \Malenki\Bah\S
or \MAlenki\Bah\A
objects:
$s = new S(' I have some white spaces ');
$s->strip;
// or
$s->strip();
$s = new S('~~.~~~I have some custom chars to remove~~~...~~');
$s->strip('.~');
// or
$s->strip(new S('.~'));
// or
$s->strip(array('.', '~'));
// or
$s->strip(new A(array('.', '~')));
You can delete some parts using range like you do it while getting substring:
$s = new S('azerty');
echo $s->delete(1, 3); // 'aty'
// or
echo $s->del(1, 3); // 'aty'
// or
echo $s->remove(1, 3); // 'aty'
// or
echo $s->rm(1, 3); // 'aty'
This class can use regex in different manners. For example, maching string can be done using two ways: the current string can be the regexp or the string to test.
First, current string is tested:
$s = new S('azerty');
var_dump($s->match('/ty$/')); // true
// or
var_dump($s->regexp('/ty$/')); // true
// or
var_dump($s->re('/ty$/')); // true
Second, current string is the pattern:
$s = new S('/ze/');
var_dump($s->test('azerty')); // true
You can cast to two different types: objects of primitive PHP types.
To cast to object, only Malenki\Bah\C
and \Malenki\Bah\N
are available
but under some conditions:
\Malenki\Bah\C
, string’s length must have exactly one character.\Malenki\Bah\N
, string must have numeric value inside itExamples:
$s = new S('a');
$s->to_c; // casts to \Malenki\Bah\C possible
$s->to_n; // casts to \Malenki\Bah\N not possible: exception
$s = new S('azerty');
$s->to_c; // casts to \Malenki\Bah\C not possible: exception
$s->to_n; // casts to \Malenki\Bah\N not possible: exception
$s = new S('3');
$s->to_c; // casts to \Malenki\Bah\C possible
$s->to_n; // casts to \Malenki\Bah\N possible
$s = new S('3.14');
$s->to_c; // casts to \Malenki\Bah\C not possible: exception
$s->to_n; // casts to \Malenki\Bah\N possible
You can cast to primitive PHP types like integer
, string
and so on. But
like you have seen into previous section, the current string must follow
some conditions to do that:
You can use two different ways to get characters into loop:
\Iterator
way\IteratorAggregate
waySo, for the first case, you will do:
$s = new S('azerty');
while($s->valid()){
$s->current(); // do something with it…
$s->next();
}
For the second case, you will do:
$s = new S('azerty');
foreach($s as $c){
$c; // do what you want with it…
}
$col_chars : \Malenki\Bah\A
Stocks characters when a call is done for that.
$col_bytes : \Malenki\Bah\A
Stocks string's bytes.
$n_length : \Malenki\Bah\N
Stocks string's length.
concat(array|\Malenki\Bah\A|\Malenki\Bah\H $params) : \Malenki\Bah\S
Concatenates string or object having toString feature together.
This can take any number of arguments. You can mix string primitive type
and oject having toString()
method implemented, like \Malenki\Bah\S
or other classes… But, you can use several arguments into a collection.
As you wish!
The returned object is from \Malenki\Bah\S
class.
If one arg is used as collection, the collection type must be array
,
\Malenki\Bah\A
object or \Malenki\Bah\H
object.
Examples:
S::concat('az', 'er', 'ty'); // S object 'azerty'
// or
S::concat(array('az', 'er', 'ty')); // S object 'azerty'
array|\Malenki\Bah\A|\Malenki\Bah\H | $params | Named of set of params to use if you want use other way than multi params. |
If one of the arguments is not
string or object having __toString()
method.
current() : \Malenki\Bah\C
Current character get into while loop using fake \Iterator way.
The current class does not implement \Iterator
interface due to
conflict with \IteratorAggregate
, but current()
feature and its
friend are implemented without the need of implement the interface!
key() : \Malenki\Bah\N
Gets current item’s key into while loop using fake \Iterator way.
The current class does not implement \Iterator
interface due to
conflict with \IteratorAggregate
, but key()
feaure is implemented
with its friends without the use of the interface!
next() : \Malenki\Bah\S
Place cursor to the next item into while loop using fake \Iterator way.
The current class does not implement \Iterator
interface due to
conflict with \IteratorAggregate
, but next()
feature is implemented
with its friend without the interface!
rewind() : \Malenki\Bah\S
Re-initialize the counter for while loop using fake \Iterator way.
Rewinds, so we can loop from the start, again.
The current class does not implement \Iterator
interface due to
conflict with \IteratorAggregate
, but rewind()
feature is
implemented with its friends!
excerpt(mixed $phrase, integer|\Malenki\Bah\N $radius) : \Malenki\Bah\S
Get an excerpt from the string surrounding by some additionnal characters.
If searched string is into the string, the returned excerpt will have the searched string surrounded by some additional chars on its left and on its right. But if the string is closed to the beginning or to the end, then, number of character may be less than you want or even be zero. This two last cases are rare, because excerpt method is used into big string.
mixed | $phrase | The searched string |
integer|\Malenki\Bah\N | $radius | Numbers of characters to display in addition of the searched string, on the left, and on the right. |
If searched string is not string or object having __toString()
method
If radius is not either integer of \Malenki\Bah\N object.
squeeze(mixed $seq) : \Malenki\Bah\S
Removes duplicate sequance of characters.
This method changes, for example, aazzzzerrtyy
to azerty
. Without
argument, it removes all found duplicates. If argument is provided, then
only given characters will be removed.
Argument can be a string, an object having __toString()
method, an
array, a \Malenki\Bah\A
or \Malenki\Bah\H
objects.
$s = new S('aazzzerrtyy');
echo $s->squeeze(); // azerty
echo $s->squeeze('az'); // azerrtyy
echo $s->squeeze(new S('az')); // azerrtyy
echo $s->squeeze(array('a','z')); // azerrtyy
If a collection is choosen, then each item must has size of one character.
If a string-like is provided, then the string will be exploded to get each characters independently.
mixed | $seq | Optionnal set of characters to squeeze |
strip(mixed $str, mixed $type) : \Malenki\Bah\S
Trims the string, by default removing white spaces on the left and on the right sides.
You can give as argument string-like or collection-like to set character(s) to strip.
Examples:
$s = new S(' azerty ');
echo $s->strip(); // 'azerty'
$s = new S(__._.__azerty___.___');
$a = array('_', '.');
$h = array('foo' => '_', 'bar' => '.');
echo $s->strip('_.'); // 'azerty'
echo $s->strip($a); // 'azerty'
echo $s->strip($h); // 'azerty'
mixed | $str | Optionnal set of characters to strip. |
mixed | $type | Optionnal type of strip, |
If str type is not allowed
If given optional type is not a string-like value.
If type does not exist
lstrip(mixed $str) : \Malenki\Bah\S
Trim the string, by default removing white spaces on the left.
You can give as argument string-like or collection-like to set character(s) to strip.
mixed | $str | Optional set of characters to strip. |
If str type is not allowed
rstrip(mixed $str) : \Malenki\Bah\S
Trim the string on its right side, by default removing white spaces.
You can give as argument string-like or collection-like to set character(s) to strip.
mixed | $str | Optional set of characters to strip. |
If str type is not allowed
trim(mixed $str, mixed $type) : \Malenki\Bah\S
Trims the string (Alias).
mixed | $str | Optionnal set of characters to strip. |
mixed | $type | Optionnal type of strip, |
If given optional type is not a string-like value.
If type does not exist
If str type is not allowed
ltrim(mixed $str) : \Malenki\Bah\S
Trims the string on the left (Alias).
mixed | $str | Optionnal set of characters to strip. |
If str type is not allowed
rtrim(mixed $str) : \Malenki\Bah\S
Trims the string on the right (Alias).
mixed | $str | Optionnal set of characters to strip. |
If str type is not allowed
append(mixed $str) : \Malenki\Bah\S
Adds string content to the end of current string.
Given argument, a string-like value, is put at the end of the string.
$s = new S('Tagada');
echo $s->append(' tsointsoin'); // 'Tagada tsointsoin'
mixed | $str | String-like content |
If given string is not… a string-like value.
after(mixed $str) : \Malenki\Bah\S
Adds content after the string (Alias).
mixed | $str | A string-like value to add |
If given string is not… a string-like value.
prepend(mixed $str) : \Malenki\Bah\S
Adds string content to the beginning of current string.
Given argument, a string-like value, is put at the beginning of the string.
$s = new S('tsointsoin !');
echo $s->prepend('Tagada '); // 'Tagada tsointsoin !'
mixed | $str | String-like content |
If given string is not… a string-like value.
before(mixed $str) : \Malenki\Bah\S
Adds content before the string.
mixed | $str | String-like content |
If given string is not… a string-like value.
surround(mixed $before, mixed $after) : \Malenki\Bah\S
Surrounds current string using starting string and ending string.
This is a short version of $s->append('foo')->prepend('bar');
.
Example:
$s = new S('foo');
echo $s->surround('(', ')'); // '(foo)'
mixed | $before | String-like starting string |
mixed | $after | String-like ending string |
If starting or ending string is not string-like value.
insert(mixed $str, mixed $pos) : \Malenki\Bah\S
Inserts new content at given position.
It is very easy to insert string into current one, if you cannot use
S::prepend()
or S::append()
, then, S::insert()
method is what you
need.
Let’s see an example:
$s = new S('abcghi');
echo $s->insert('def', 3); // 'abcdefghi'
mixed | $str | String-like content |
mixed | $pos | Integer-like content (integer or \Malenki\Bah\N object) |
If given string is not valid
If given position is not valid.
put(mixed $str, mixed $pos) : \Malenki\Bah\S
Inserts new content at given position (Alias).
mixed | $str | String-like content |
mixed | $pos | Integer-like content |
If given string is not valid
If given position is not valid.
camelCase(boolean $is_upper) : \Malenki\Bah\S
Convert current string in camelCase or CamelCase.
By default, this will create new string as lower camel case. But if
argument is true
, then returned string will be in upper camel case.
Examples:
$s = new S('Helloi World!');
echo $s->camelCase(); // 'helloWorld'
echo $s->camelCase(true); // 'HelloWorld'
Note: This does not convert characters having diacritic, to to that,
call S::$trans
magic getter before:
$s = new S('Écrit en français !');
echo $s->lcc; // 'écritEnFrançais'
echo $s->trans->lcc; // 'ecritEnFrancais'
In this previous example, I used one magic getter alias lcc
of this
method.
boolean | $is_upper |
|
lowerCamelCase() : \Malenki\Bah\S
Gets string converted in lower camel case.
This is an alias of \Malenki\Bah\S::camelCase()
.
upperCamelCase() : \Malenki\Bah\S
Gets string converted in upper camel case.
This is an alias of \Malenki\Bah\S::camelCase()true.
sub(mixed $offset, mixed $limit) : \Malenki\Bah\S
Get substring from the original string.
By default, returns the first character as a substring.
Getting substring is simple. First, set the starting point, an index from 0 to length of the string less one. Seconde, set the size, if not given, it is one character.
Example:
$s = new S('azerty');
echo $s->sub(); // 'a'
echo $s->sub(1, 3); // 'zer'
mixed | $offset | Where to start the substring, 0 by default, as N or
|
mixed | $limit | Size of the substring, 1 by default, as N or
|
If offset is not an Integer-like
If offset is not valid
If limit is not an Integer-like
If limit is negative
position(mixed $needle) : \Malenki\Bah\A
Gets all available positions of given string needle.
Unlike its PHP equivalent function, it returns all found positions
as a \Malenki\Bah\A
object. If no position found, this returns object as
void collection.
Example:
$s = new S('Tagada tsointsoin !');
$s->position('tsoin'); // Collection having 7 and 12 as \Malenki\Bah\N
mixed | $needle | The searched string-like content |
If needle is not a string-like value
If needle is empty
pos(mixed $needle) : \Malenki\Bah\A
Gets all available positions of given string needle (Alias).
mixed | $needle | The searched string-like content |
If needle is not a string-like value
If needle is empty
delete(integer|\Malenki\Bah\N $offset, integer|\Malenki\Bah\N $limit) : \Malenki\Bah\S
Removes string part using offset and limit size.
To delete string part, you must give index from where to start, thinking about the starting point of the string is zero. Then, you must define the length of the part to remove.
A little example show you how to do that:
$s = new S('This string will loose some parts…');
$s->delete(4, 7); // 'This will loose some parts…'
integer|\Malenki\Bah\N | $offset | Integer-like offset |
integer|\Malenki\Bah\N | $limit | Integer-like limit size |
If offset is not an integer-like
If offset is negative
If limite is not an integer-like
del(mixed $offset, mixed $limit) : \Malenki\Bah\S
Removes string part using offset and limit size (Alias).
mixed | $offset | Integer-like offset |
mixed | $limit | Integer-like limit size |
If offset is not an integer-like
If offset is negative
If limite is not an integer-like
remove(mixed $offset, mixed $limit) : \Malenki\Bah\S
Removes string part using offset and limit size (Alias).
mixed | $offset | Integer-like offset |
mixed | $limit | Integer-like limit size |
If offset is not an integer-like
If offset is negative
If limite is not an integer-like
rm(mixed $offset, mixed $limit) : \Malenki\Bah\S
Removes string part using offset and limit size (Alias).
mixed | $offset | Integer-like offset |
mixed | $limit | Integer-like limit size |
If offset is not an integer-like
If offset is negative
If limite is not an integer-like
match(mixed $expr) : boolean
Checks string using Regexp
Checks whether current string match the given regular expression.
Example:
$s = new S('azerty');
var_dump($s->match('/ty$/')); // true
mixed | $expr | primitive string or object having __toString method |
If regexp pattern is not a string-like value.
test(mixed $str) : boolean
Tests given string using regex pattern stored into current string.
Acts as current string is regex pattern, then, string passed to the argument of this method will be tested using current string.
Example:
$s = new S('/ze/');
var_dump($s->test('azerty')); // true
mixed | $str | A string-like to test |
If argument is not a string-like or a scalar.
title(mixed $sep) : \Malenki\Bah\S
Converts the string to upper case words.
This is equivalent of basic PHP function ucwords()
But enhances for
UTF-8 and use of additionnal separators to split string into words.
So, this feature can use magic getter or method way, and some alias are available too.
Examples:
$s = new S("C'est du français !"); // note the apos after this example…
echo $s->title; // 'C'est Du Français !'
echo $s->title("'"); // 'C'Est Du Français !'
mixed | $sep | Optionnal sequence of additionnal separators. |
If not null sep has not right type or contains bad type.
ucw(mixed $sep) : \Malenki\Bah\S
Converts the string to upper case words (Alias).
mixed | $sep | Optionnal sequence of additionnal separators. |
If not null sep has not right type or contains bad type.
ucwords(mixed $sep) : \Malenki\Bah\S
Converts the string to upper case words (Alias).
mixed | $sep | Optionnal sequence of additionnal separators. |
If not null sep has not right type or contains bad type.
upperCaseWords(mixed $sep) : \Malenki\Bah\S
Converts the string to upper case words (Alias).
mixed | $sep | Optionnal sequence of additionnal separators. |
If not null sep has not right type or contains bad type.
charAt(integer|\Malenki\Bah\N $idx) : \Malenki\Bah\C
Get character at the given position.
Position start from 0 to end at string’s length less one.
Note: Returned object is not a \Malenki\Bah\S
object, but a
\Malenki\Bah\C
object, to deal with all character’s features.
$s = new S('abc');
$s->charAt(0)->unicode; // print unicode value of the char 'a'
integer|\Malenki\Bah\N | $idx | The index where the character is, as N or integer. |
If index is not an integer-like.
If index does not exist.
take(integer|\Malenki\Bah\N $idx) : \Malenki\Bah\C
Alias of charAt() method
integer|\Malenki\Bah\N | $idx | Position as integer-like |
at(integer|\Malenki\Bah\N $idx) : \Malenki\Bah\C
Alias of charAt() method
integer|\Malenki\Bah\N | $idx | Position as integer-like |
times(mixed $n) : \Malenki\Bah\S
Repeats N times current string.
Repeats N times current string. Number of times can be zero to, so resulting string is void.
Example:
$s = new S('Hello!');
echo $s->append(' ')->times(3)->strip; // 'Hello! Hello! Hello!'
echo $s->times(0); // '' (empty string)
mixed | $n | Integer-like value |
If N is not an integer-like.
If N is negative
repeat(mixed $n) : \Malenki\Bah\S
Repeats N times current string (Alias).
mixed | $n | Integer-like value |
If N is not an integer-like.
If N is negative
wrap(integer|\Malenki\Bah\N $width, mixed $cut) : \Malenki\Bah\S
Wraps the string to fit given width.
If the curent string’s size equals or is less than size to fit the result, then nothing appens. If the string is greater than wanted with, then the string is wrapped.
An example resulti using this method could be:
Tous les êtres
humains naissent
libres et égaux en
dignité et en
droits. Ils sont
doués de raison et
de conscience et
doivent agir les
uns envers les
autres dans un
esprit de
fraternité.
integer|\Malenki\Bah\N | $width | Width the text must have |
mixed | $cut | Optional string to put at each linebreak, as
|
If width is not an integer-like
If cut is not a string-like
margin(mixed $left, mixed $right, mixed $alinea) : \Malenki\Bah\S
Adds margin to the text. By default left, but right and alinea are possible too.
This is greet for raw text outputs.
This is a good complement of S::wrap()
method.
Example using all arguments, to have idea of available possibilities
$s = new S('Tous les…'); // long text
echo 'First: ';
echo $s->wrap(40)->margin(10, 0, -7);
This example will print:
First: Tous les êtres humains naissent libres
et égaux en dignité et en droits. Ils
sont doués de raison et de conscience
et doivent agir les uns envers les
autres dans un esprit de fraternité.
mixed | $left | Margin left (N or integer) |
mixed | $right | Margin right, optional (N or integer) |
mixed | $alinea | First line, optional (N or integer) |
If margin left, margin right or alinea is not an integer-like.
If margin left and/or right are negative
If alinea is greater than margin left
center(integer|\Malenki\Bah\N $width, mixed $cut) : \Malenki\Bah\S
Centers text to fit on given width, padding with spaces.
This is usefull for pure text output (email, console, content on PRE
HTML tag…)
Example result:
Tous les êtres humains naissent libres
et égaux en dignité et en droits. Ils
sont doués de raison et de conscience
et doivent agir les uns envers les
autres dans un esprit de fraternité.
integer|\Malenki\Bah\N | $width | Width to fit. If not given, default used is 79 chars width. |
mixed | $cut | Optional string-like at end of line to use. Default is |
If width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
left(mixed $width, mixed $cut) : \Malenki\Bah\S
Left aligns text to fit it into the given width.
If width is not set, then width is set to 79 characters.
Gap is filled with spaces.
An optional string can be set to have
different end of line, by default, PHP_EOL
is used.
This method is usefull for text into console, pure text output or
content to place into PRE
balise in HTML.
mixed | $width | Width to fit in, an integer-like. Default is 79. |
mixed | $cut | String at the end of each line, by default it is |
If Width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
ljust(mixed $width, mixed $cut) : \Malenki\Bah\S
Left aligns text to fit it into the given width (alias).
mixed | $width | Width to fit in, an integer-like. Default is 79. |
mixed | $cut | String at the end of each line, by default it is |
If Width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
leftAlign(mixed $width, mixed $cut) : \Malenki\Bah\S
Left aligns text to fit it into the given width (alias).
mixed | $width | Width to fit in, an integer-like. Default is 79. |
mixed | $cut | String at the end of each line, by default it is |
If Width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
leftJustify(mixed $width, mixed $cut) : \Malenki\Bah\S
Left aligns text to fit it into the given width (alias).
mixed | $width | Width to fit in, an integer-like. Default is 79. |
mixed | $cut | String at the end of each line, by default it is |
If Width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
right(mixed $width, mixed $cut) : \Malenki\Bah\S
Right aligns text to fit it into the given width.
If width is not set, then width is set to 79 characters.
Gap is filled with spaces.
An optional string can be set to have
different end of line, by default, PHP_EOL
is used.
This method is usefull for text into console, pure text output or
content to place into PRE
balise in HTML.
One example of string output by this method using width of 40 could be:
Tous les êtres humains naissent libres
et égaux en dignité et en droits. Ils
sont doués de raison et de conscience
et doivent agir les uns envers les
autres dans un esprit de fraternité.
mixed | $width | Width to fit in, an integer-like. Default is 79. |
mixed | $cut | String at the end of each line, by default it is |
If Width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
rjust(mixed $width, mixed $cut) : \Malenki\Bah\S
Right aligns text to fit it into the given width (alias).
mixed | $width | Width to fit in, an integer-like. Default is 79. |
mixed | $cut | String at the end of each line, by default it is |
If Width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
rightAlign(mixed $width, mixed $cut) : \Malenki\Bah\S
Right aligns text to fit it into the given width (alias).
mixed | $width | Width to fit in, an integer-like. Default is 79. |
mixed | $cut | String at the end of each line, by default it is |
If Width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
rightJustify(mixed $width, mixed $cut) : \Malenki\Bah\S
Right aligns text to fit it into the given width (alias).
mixed | $width | Width to fit in, an integer-like. Default is 79. |
mixed | $cut | String at the end of each line, by default it is |
If Width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
justify(mixed $width, string $last_line, mixed $cut) : \Malenki\Bah\S
Justify text, into given width.
This allows you to justify text. To do that, you can call it without any
argument, so, the default width is 79 characters, last line is align on
the left and line end is PHP_EOL
.
If you want customize the justifying, then, width is an integer-like,
last line type must be either left
or right
, and end of line can be
any string-like you want.
Spaces are added to reproduce this justifying effect. Very great for non-HTML text ouputs, like email, text file, log, console…
One example with a long string justifying into width of 40 chars:
Tous les êtres humains naissent libres
et égaux en dignité et en droits. Ils
sont doués de raison et de conscience
et doivent agir les uns envers les
autres dans un esprit de fraternité.
mixed | $width | Width as integer-like to fit resulting string in. Optional, default is 79 characters. |
string | $last_line | Last line type as string-like. Optional, by
default set to |
mixed | $cut | End of line string-like. Optional, set by default at
|
If given type is not left
or right
.
If width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
explode(mixed $sep) : \Malenki\Bah\A
Splits the string using Regexp.
Argument is a string-like value containing regexp matching the separator sued to split the string.
Example:
$s = new S('This is a string to split');
$s->explode('/\s+/'); // 'This', 'is', 'a', 'string', 'to' and ' split'
mixed | $sep | String-like regex |
Regexp is void
split(mixed $sep) : \Malenki\Bah\A
Splits the string using Regexp.
mixed | $sep | String-like regex |
Regexp is void
cut(mixed $sep) : \Malenki\Bah\A
Splits the string using Regexp.
mixed | $sep | String-like regex |
Regexp is void
chunk(integer|\Malenki\Bah\N $size) : \Malenki\Bah\A
Cuts the string as a set of substrings having given size.
Each substring is a \Malenki\Bah\S
object. The set of this objects is
put into an \Malenki\Bah\A
object.
So, let's chunk a string to see what we get:
$s = new S('azertyuiop');
var_dump($s->chunk(3)->array);
This will give an array having the following set of \Malenki\Bah\S
:
aze
, rty
, uio
and p
.
Note: This method can be used as magic getter too. In this case, it will split the string into substring having one character. Example:
$s = new S('azerty');
echo $s->chunk->join(','); // 'a,z,e,r,t,y'
integer|\Malenki\Bah\N | $size | If not given, its default value is 1. |
If size is not an integer-like.
If chunk's size is less than one.
replace(mixed $pattern, mixed $string) : \Malenki\Bah\S
Replace some parts of current string using Regexp
This acts like preg_replace()
function. The first argument is the
pattern to match, the second is the replacement string.
Example:
$s = new S('azerty');
echo $s->replace('/aey/', '!'); // '!z!rt!'
Each param can be string or object having __toString()
method.
mixed | $pattern | Pattern to match. A string-like type. |
mixed | $string | String to put in place of matching parts. |
If one of the arguments is not a string-like type.
change(mixed $pattern, mixed $string) : \Malenki\Bah\S
Change matching parts of the string using Regexp (Alias).
mixed | $pattern | Pattern to match. A string-like type. |
mixed | $string | String to put in place of matching parts. |
If one of the arguments is not a string-like type.
format(array|\Malenki\Bah\A|\Malenki\Bah\H $params) : \Malenki\Bah\S
Use current string as format for given params, it is a `sprintf`-like
This method acts as sprintf()
, using current string as format string.
So, it can take any number of arguments of any "stringable" type. But
you can also use one argument if this is a set of params. So, you have
two different ways to use it.
A litle example to show it in action:
$s = new S('I will have %s data to %s.');
echo $s->format('some', new S('show')); // 'I will have some data to show.'
// or
$s = new S('I will have %s data to %s.');
$params = array('some', new S('show')); // or A or H object too
echo $s->format($params); // 'I will have some data to show.'
Note: Object of type \Malenki\Bah\N
can be used too.
$n = new N(M_PI);
$s = new S('I am pi: %1.3f')
echo $s->format($n); // 'I am pi: 3.142'
array|\Malenki\Bah\A|\Malenki\Bah\H | $params | Named of set of params to use if you want use other way than multi params. |
If at least one argument is not a
scalar or an object having __toString()
method.
sprintf(array|\Malenki\Bah\A|\Malenki\Bah\H $params) : \Malenki\Bah\S
Use current string as format for given params, it is a `sprintf`-like (Alias).
array|\Malenki\Bah\A|\Malenki\Bah\H | $params | Named of set of params to use if you want use other way than multi params. |
If at least one argument is not a
scalar or an object having __toString()
method.
fmt(array|\Malenki\Bah\A|\Malenki\Bah\H $params) : \Malenki\Bah\S
Use current string as format for given params, it is a `sprintf`-like (Alias).
array|\Malenki\Bah\A|\Malenki\Bah\H | $params | Named of set of params to use if you want use other way than multi params. |
If at least one argument is not a
scalar or an object having __toString()
method.
set(integer|\Malenki\Bah\N $idx, mixed $char) : \Malenki\Bah\S
Sets one character at given position.
This change one character of the string. Example:
$s = new S('azerty');
echo $s->set(1, 'b'); // aberty
integer|\Malenki\Bah\N | $idx | Index of an existing position, as integer-like |
mixed | $char | New character to set, as string-like. |
If index is not an integer-like.
If index does not exist.
If New character is not a string-like type.
If new character is not a string-like having a size of one.
detab(mixed $n, string $eol) : \Malenki\Bah\S
Replaces tabulations into a string by spaces.
Replaces tabulations into a string by spaces, given size and into all the lines. If EOL into string is not LF, then you must give yours into second parameters.
$s = new S("\t\tThis is a\tstring having\ttabulations");
echo $s->detab(4); // ' This is a string having tabulations'
mixed | $n | An integer-like value for tab size. |
string | $eol | Optionnal parameter to set default EOL to use. |
If tab's size is no integer-like value
If tab's size is equal to or inférior to zero
untag(mixed $tag) : \Malenki\Bah\S
Removes HTML and XML tags.
Returns current string without any tags. You can preserves some of them using string-like values or collection and/or DOMNode/DOMElement.
Example:
$s = new S('<p>I have <em>some</em> <strong>tags</strong></p>');
echo $s->untag; // 'I have some tags'
echo $s->untag('em'); // 'I have <em>some</em> tags'
echo $s->untag('<em>'); // 'I have <em>some</em> tags'
echo $s->untag('em strong'); // 'I have <em>some</em> <strong>tags</strong>'
echo $s->untag('em,strong'); // 'I have <em>some</em> <strong>tags</strong>'
echo $s->untag('em;strong'); // 'I have <em>some</em> <strong>tags</strong>'
echo $s->untag('em|strong'); // 'I have <em>some</em> <strong>tags</strong>'
echo $s->untag('<em><strong>'); // 'I have <em>some</em> <strong>tags</strong>'
echo $s->untag(array('em', 'strong')); // 'I have <em>some</em> <strong>tags</strong>'
echo $s->untag(array('<em>', '<strong>')); // 'I have <em>some</em> <strong>tags</strong>'
$a = new A();
$a->add('em')->add('strong');
echo $s->untag($a); // 'I have <em>some</em> <strong>tags</strong>'
$dom = new \DOMDocument('1.0');
$strong = $dom->createElement('strong');
$em = $dom->createElement('em');
echo $s->untag($strong); // 'I have some <strong>tags</strong>'
echo $s->untag(array($strong, $em)); // 'I have <em>some</em> <strong>tags</strong>'
mixed | $tag | Tag(s) to keep |
If invalid type is used.
stripTags(mixed $tag) : \Malenki\Bah\S
Removes HTML and XML tags (Alias).
mixed | $tag | Tag(s) to keep |
If invalid type is used.
n(boolean $after) : \Malenki\Bah\S
Add new line as LF.
This is shorthand to avoid concatenating Line Feed character to the current string.
It can be used as magic getter to, in this case, appending way is used.
Examples:
$s = new S('azerty');
echo "$s\n"; // "azerty\n"
echo $s . "\n"; // "azerty\n"
echo $s->n; // "azerty\n"
echo $s->n(false); // "\nazerty"
boolean | $after | If false, put new line before the string |
r(boolean $after) : \Malenki\Bah\S
Add new line as CR.
This is shorthand to avoid concatenating CR aka Cariage Return to the current string.
It can be used as magic getter to, in this case, appending way is used.
Examples:
$s = new S('azerty');
echo "$s\r"; // "azerty\r"
echo $s . "\r"; // "azerty\r"
echo $s->r; // "azerty\r"
echo $s->r(false); // "\razerty"
boolean | $after | If false, put new line before the string |
eof(boolean $after) : \Malenki\Bah\S
Add PHP_EOL at the end or at the beginning.
This is shorthand to avoid concatenating PHP_EOL used by the system to the current string.
It can be used as magic getter to, in this case, appending way is used.
Examples (PHP_EOL == "\n"
):
$s = new S('azerty');
echo $s . PHP_EOL; // "azerty\n"
echo $s->eol; // "azerty\n"
echo $s->eol(false); // "\nazerty"
boolean | $after | If false, put new line before the string |
rn(boolean $after) : \Malenki\Bah\S
Add CRLF sequence at the end or at the beginning.
This is shorthand to avoid concatenating CRLF aka Cariage Return Line Feed to the current string.
It can be used as magic getter to, in this case, appending way is used.
Examples:
$s = new S('azerty');
echo "$s\r\n"; // "azerty\r\n"
echo $s . "\r\n"; // "azerty\r\n"
echo $s->rn; // "azerty\r\n"
echo $s->rn(false); // "\r\nazerty"
boolean | $after | If false, put new line before the string |
mustBeStringOrScalar(mixed $arg, string $arg_name) : void
Checks whether given value is string-like or scalar type.
Value must be of string-like type (string or object having
__toString()
method) or a basic scalar type.
The aim of this method is only to raise \InvalidArgumentException
if
given value has not the good type.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
mustBeString(mixed $arg, string $arg_name) : void
Checks whether given value is string-like type.
A string-like value is string or object having __toString()
method.
The aim of this method is only to raise \InvalidArgumentException
if
given value has not the good type.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
mustBeInteger(mixed $arg, string $arg_name) : void
Checks whether given value is integer-like type.
An integer-like value is integer or \Malenki\Bah\N
object.
The aim of this method is only to raise \InvalidArgumentException
if
given value has not the good type.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
mustBeFloat(mixed $arg, string $arg_name) : void
Checks whether given value is float-like type.
A float-like value is float or \Malenki\Bah\N
object.
The aim of this method is only to raise \InvalidArgumentException
if
given value has not the good type.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
mustBeDouble(mixed $arg, string $arg_name) : void
Checks whether given value is double-like type.
A double-like value is string or \Malenki\Bah\N
object.
The aim of this method is only to raise \InvalidArgumentException
if
given value has not the good type.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
mustBeNumeric(mixed $arg, string $arg_name) : void
Checks whether given value is numeric-like type.
A numeric-like value is numeric (integer, float or double) or
\Malenki\Bah\N
object.
The aim of this method is only to raise \InvalidArgumentException
if
given value has not the good type.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
mustBeArray(mixed $arg, string $arg_name) : void
Checks whether given value is an array-like type.
A array-like value is an array or \Malenki\Bah\A
object.
The aim of this method is only to raise \InvalidArgumentException
if
given value has not the good type.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
mustBeHash(mixed $arg, string $arg_name) : void
Checks whether given value is a hash-like type.
A hash-like value is an array having named-index or \Malenki\Bah\H
object.
The aim of this method is only to raise \InvalidArgumentException
if
given value has not the good type.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
mustBeArrayOrHash(mixed $arg, string $arg_name) : void
Checks whether given value is an array-like or hash-like type.
The aim of this method is only to raise \InvalidArgumentException
if
given value has not the good type.
mixed | $arg | The value to test. |
string | $arg_name | Optional name of the value, used into exception’s message. |
If value’s type is not valid
mustBeCallable(mixed $arg, mixed $arg_name) : void
Checks whether the given argument is callable.
This is usefull to test is an argument can be call as a function. If
this argument is not callable, then this raises an
\InvalidArgumentException
.
mixed | $arg | The value to test |
mixed | $arg_name | Optional name of the value, used into error message |
If arg is not callable
_chars() : \Malenki\Bah\A
Create \Malenki\Bah\C collection from the string
This explode the string into characters, each of them is instanciated as
\Malenki\Bah\C
object into \Malenki\Bah\A
collection.
This method is the back side of magic getter \Malenki\Bah\S::$chars
_bytes() : \Malenki\Bah\A
Create bytes collection from the string.
This create collection of bytes as \Malenki\Bah\N
object stored into
\Malenki\Bah\A
collection.
This method is the back side of magic getter \Malenki\Bah\S::$bytes
_length() : \Malenki\Bah\A
Compute the string’s length as \Malenki\Bah\N object
Defines the magic getter \Malenki\BahS::$length
to have quick access
to characters' number contained into the string as \Malenki\Bah\N
object.
Note: This is equivalent of \Malenki\Bah\S::count()
defined by
\Countable
interface, but here, \Malenki\Bah\N
object is returned,
not an int
.
_to(string $name) : \Malenki\Bah\C|\Malenki\Bah\N
Convert current object to other object type.
You can only convert to \Malenki\Bah\C
object or \Malenki\Bah\N
object.
string | $name | Either |
If you try converting to \Malenki\Bah\C object a string having more than one character.
If you try cinverting string having not numeric value to \Malenki\Bah\N object.
_integer() : integer
Converts current string object to integer primitive type.
This method is the runtime part of magic getter
\Malenki\Bah\S::$integer
.
This works only if the string has numeric value inside it. If this is
not the case, then it raises \RuntimeException
.
$s = new S('12');
var_dump($s->integer); // type 'int'
If numeric value is float, then returns only its integer part.
$s = new S('3.14');
var_dump($s->integer); // 3
If current string has not numeric value.
_float() : integer
Converts current string object to float primitive type.
This method is the runtime part of magic getter
\Malenki\Bah\S::$float
.
This works only if the string has numeric value inside it. If this is
not the case, then it raises \RuntimeException
.
$s = new S('3.14');
var_dump($s->float); // 3.14
If current string has not numeric value.
_double() : integer
Converts current string object to double primitive type.
This method is the runtime part of magic getter
\Malenki\Bah\S::$float
.
This works only if the string has numeric value inside it. If this is
not the case, then it raises \RuntimeException
.
$s = new S('3.14');
var_dump($s->double); // 3.14
If current string has not numeric value.
_trans() : \Malenki\Bah\S
Transliterates the string.
This transforms the string to remove all its diacritics, to have as result a string containing only ASCII-like characters.
This feature is called by using magic getter version only.
Example:
$s = new S('C’est écrit en français !');
echo $s->trans; // 'C’est ecrit en francais !'
Warning: This requires the Intl PHP extension! If you try to use
this method without it, you will get an \RuntimeException
. Please see
Intl section on the PHP
official website if you have not this extension installed yet.
Warning 2: This cannot work on PHP version < 5.4.0! Even if Intl is installed, this provided translitterated feature only into PHP 5.4.0+
If this is called and intl extension is not installed.
If intl extension is installed but that uses PHP version prior to 5.4.0.
_slug() : \Malenki\Bah\S
Creates slug for current string.
This transliterate characters into latin characters without any diacritic, converts to lower cases and uses dashes to separate each words.
Example:
$s = new S('Je suis écrit en français !');
echo $s->slug; // 'je-suis-ecrit-en-francais'
This method is the running part of magic getter having same name.
This method is in fact a shorthand for $s->lower->trans->dash;
call.
If this is called and intl extension is not installed.
If intl extension is installed but that uses PHP version prior to 5.4.0.
_swapCase() : \Malenki\Bah\S
Swaps cases.
This converts lower cases to upper cases and vice versa.
This is used only into magic getter context.
Example:
$s = new S('AzeRtY');
echo $s->swap; // 'aZErTy'
_underscore() : \Malenki\Bah\S
Convert string using underscore
The string is converted to lower cases, each character that is not a letter, a digit or an underscore is replaced by underscore and then duplicate underscores are removed. Heading and trailing underscores are removed.
This method is used only to implement magic getter versions.
Example:
$s = new S('Je suis écrit en français !');
echo $s->underscore; // 'je_suis_écrit_en_français'
echo $s->_; // 'je_suis_écrit_en_français'
_dash() : \Malenki\Bah\S
Convert string using dashes
The string is converted to lower cases, each character that is not a letter, a digit or a dash is replaced by dash and then duplicate dashes are removed. Heading and trailing dashes are removed.
This is hyphen version of \Malenki\Bah\S::_underscore()
.
This method is used only to implement magic getter versions.
Example:
$s = new S('Je suis écrit en français !');
echo $s->dash; // 'je-suis-écrit-en-français'
_first() : \Malenki\Bah\S
Gets the first character as \Malenki\Bah\S object.
This is runtime part of magic getter \Malenki\Bah\S::$first
.
$s = new S('azerty');
echo $s->first; // print 'a'
If you want first character as \Malenki\Bah\C
object, then, do one of the followings:
$s = new S('azerty');
$s->chars->first; // first \Malenki\Bah\C
// or
$s->first->to_c; // casting \Malenki\Bah\S to \Malenki\Bah\C
_last() : \Malenki\Bah\S
Gets the last character as \Malenki\Bah\S object.
This is runtime part of magic getter \Malenki\Bah\S::$last
.
$s = new S('azerty');
echo $s->last; // print 'y'
If you want last character as \Malenki\Bah\C
object, then, do one of the followings:
$s = new S('azerty');
$s->chars->last; // last \Malenki\Bah\C
// or
$s->last->to_c; // casting \Malenki\Bah\S to \Malenki\Bah\C
_upperCaseFirst() : \Malenki\Bah\S
Converts to upper case first.
Converts the first character to upper case.
_upper() : \Malenki\Bah\S
Returns new string object converted to uppercase.
_lower() : \Malenki\Bah\S
Returns new string object converted to lowercase.
_leftOrRightJustify(string $type, integer $width, string $cut) : \Malenki\Bah\S
Justify text on the left or on the right, to fit on given width padding with spaces.
This is usefull for pure text output (email, console, content on PRE
HTML tag…)
string | $type | Must be either |
integer | $width | Width to fit. If not given, default used is 79 chars width. |
string | $cut | Optional string at end of line to use. Default is |
If given type is not left
or right
.
If width is not an integer-like.
If width is negative or null.
If cut end of line string is not string-like.
_rtl() : boolean
Checks whether the whole string is right to left.
Some languages, like Arabic language, writes their sentences from right to left.
This method allows you to check is whole content of the string is written right to left.
This method is used only throught magic getters. Let’s see some examples:
$s = new S('أبجد');
var_dump($s->rtl); // true
var_dump($s->is_rtl); // true
var_dump($s->is_right_to_left); // true
var_dump($s->right_to_left); // true
_ltr() : boolean
Checks whether the whole string is written from the left to the right.
Many languages are written from left or right, but some other not. So, this method tests if the current string is LTR.
This method is used only throught magic getters. Let’s see some examples:
$s = new S('Je suis écrit en français !');
var_dump($s->ltr); // true
var_dump($s->is_ltr); // true
var_dump($s->is_left_to_right); // true
var_dump($s->left_to_right); // true
_hasMixedDirection() : boolean
Tests whether the current string has both RTL and LTR parts
This is runtime version for some magic getters. This returns true
if,
for example, the string contains both french and arabic text.
$s = new S(
'Ceci est du français contenant le mot '
.'arabe أبجد qui veut dire "abjad".'
);
var_dump($s->has_mixed_direction); // true
var_dump($s->mixed_direction); // true
var_dump($s->is_ltr_and_rtl); // true
var_dump($s->ltr_and_rtl); // true
var_dump($s->is_rtl_and_ltr); // true
var_dump($s->rtl_and_ltr); // true
_zorg() : \Malenki\Bah\S
Converts string into Zorglub’s language.
Yes, this is an Easter Egg:)
Example:
$s = new S('Je suis Fantasio ! C‘est bien connu bon sang !');
echo $s->zorg; // 'Ej sius Oisatnaf ! C‘tse neib unnoc nob gnas !'
_md5() : \Malenki\Bah\S
Computes the MD5 sum of the string.
This method compute the MD5 sum of its internal value and returns the
result as a \Malenki\Bah\S
object.
Example:
$s = new S('Hello!');
print($s->md5); // '952d2c56d0485958336747bcdd98590d'
_sha1() : \Malenki\Bah\S
Compute the SHA1 sum of the string.
This method compute the SHA1 sum of its internal value and returns the
result as a \Malenki\Bah\S
object.
Example:
$s = new S('Hello!');
print($s->sha1); // '69342c5c39e5ae5f0077aecc32c0f81811fb8193'
_formatEngine(mixed $args) : \Malenki\Bah\S
_formatEngine
mixed | $args |
_nl(string $type, boolean $after) : \Malenki\Bah\S
Add new CR, LF, CRLF or PHP_EOL before or after the string.
This is used as engine for several methods and magic getters into this class.
As first argument, it takes string to define the new line: \n
, \r
,
\r\n
or PHP_EOL
. The second argument is boolean: true
(default)
puts the new line after the string, false
puts he new line at the
beginning of the string.
string | $type | One of this string: |
boolean | $after | Set to |