\Malenki\BahS

Play with Strings!

Checking

Starts or ends with…

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

Checking whether the string is void

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

LTR, RTL or both?

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!

Getting informations

Counts

You can get counts of chars or of bytes contained into the string using 3 ways:

  • the count() function (\Malenki\Bah\S implements \Countable interface), returns number of characters as primitive integer value
  • the S::$length magic getter, returns number of characters as \Malenki\Bah\N object
  • the S::$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)
}

Finger prints

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'

Getting parts

Getting character(s)

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

Getting substring(s)

You have many ways to get substrings, you can explode the string, take range of characters, take some part matching some regexp…

Explode everything!

You have two different ways to explode your string into simple manner.

  • By using a given regexp as separator
  • By cutting each N characters.

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'

Classical substring way…

You can extract substring by given start position and the length of the substring.

$s = new S('azerty');
echo $s->sub(1, 3); // 'zer'

Adding content to it

Prepend, append

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.

Inserting 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));

Repeat again and again…

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.

Adding new line

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"

Join several strings together

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'

Changing some parts

Soon…

Removing some parts

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!

Stripping

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('.', '~')));

Deleting using ranges

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'

Regular expression

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

Casting

You can cast to two different types: objects of primitive PHP types.

Casting to objects

To cast to object, only Malenki\Bah\C and \Malenki\Bah\N are available but under some conditions:

  • To cast to \Malenki\Bah\C, string’s length must have exactly one character.
  • To cast to \Malenki\Bah\N, string must have numeric value inside it

Examples:

$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

Casting to primitive types

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:

  • to integer: string must contain numeric value
  • to float/double: string must have numeric value

Looping

You can use two different ways to get characters into loop:

  • the fake \Iterator way
  • the \IteratorAggregate way

So, 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…
 }

Summary

Methods
Properties
Constants
__get()
__toString()
concat()
__construct()
getIterator()
current()
key()
next()
rewind()
valid()
excerpt()
squeeze()
strip()
lstrip()
rstrip()
trim()
ltrim()
rtrim()
append()
after()
prepend()
before()
surround()
insert()
put()
camelCase()
lowerCamelCase()
upperCamelCase()
sub()
position()
pos()
delete()
del()
remove()
rm()
startsWith()
endsWith()
match()
regexp()
re()
test()
title()
ucw()
ucwords()
upperCaseWords()
charAt()
take()
at()
count()
times()
repeat()
wrap()
margin()
center()
left()
ljust()
leftAlign()
leftJustify()
right()
rjust()
rightAlign()
rightJustify()
justify()
explode()
split()
cut()
chunk()
replace()
change()
format()
sprintf()
fmt()
set()
detab()
untag()
stripTags()
n()
r()
eof()
rn()
$chars
$bytes
$length
$to_c
$to_n
$n
$r
$rn
$eol
$is_void
$void
$is_empty
$empty
$strip
$lstrip
$rstrip
$trim
$ltrim
$rtrim
$sub
$chunk
$delete
$remove
$del
$rm
$center
$left
$left_justify
$left_align
$ljust
$right
$right_justify
$right_align
$rjust
$justify
$just
$wrap
$underscore
$_
$dash
$upper_camel_case
$lower_camel_case
$cc
$lcc
$ucc
$lower
$upper
$first
$last
$title
$ucw
$ucwords
$upper_case_words
$trans
$md5
$sha1
$swap_case
$swapcase
$swap
$squeeze
$ucf
$ucfirst
$upper_case_first
$string
$str
$integer
$int
$float
$double
No constants found
mustBeStringOrScalar()
mustBeString()
mustBeInteger()
mustBeFloat()
mustBeDouble()
mustBeNumeric()
mustBeArray()
mustBeHash()
mustBeArrayOrHash()
mustBeCallable()
_chars()
_bytes()
_length()
_to()
_string()
_str()
_integer()
_int()
_float()
_double()
_trans()
_slug()
_swapCase()
_underscore()
_dash()
_first()
_last()
_upperCaseFirst()
_isVoid()
_upper()
_lower()
_leftOrRightJustify()
_rtl()
_ltr()
_hasMixedDirection()
_zorg()
_md5()
_sha1()
$value
$col_chars
$col_bytes
$n_length
$int_count
$position
N/A
_formatEngine()
_nl()
No private properties found
N/A

Properties

$chars

$chars : \Malenki\Bah\A

A collection of Malenki\Bah\C objects.

Type

\Malenki\Bah\A

$bytes

$bytes : \Malenki\Bah\A

A collection of Malenki\bah\N objects

Type

\Malenki\Bah\A

$length

$length : \Malenki\Bah\N

The strings length

Type

\Malenki\Bah\N

$to_c

$to_c : \Malenki\Bah\C

If string as only one character, convert it to \Malenki\Bah\C object.

Type

\Malenki\Bah\C

$to_n

$to_n : \Malenki\Bah\N

If string contents numeric value, try to export it to \Malenki\Bah\N object.

Type

\Malenki\Bah\N

$n

$n : \Malenki\Bah\S

Return itself + LF '\n'

Type

\Malenki\Bah\S

$r

$r : \Malenki\Bah\S

Return itself + CR '\r'

Type

\Malenki\Bah\S

$rn

$rn : \Malenki\Bah\S

Return itself + CRLF '\r\n'

Type

\Malenki\Bah\S

$eol

$eol : \Malenki\Bah\S

Return itself + PHP_EOL

Type

\Malenki\Bah\S

$is_void

$is_void : boolean

Tests whether the current string is void or not.

Type

boolean

$void

$void : boolean

Tests whether the current string is void or not.

Type

boolean

$is_empty

$is_empty : boolean

Tests whether the current string is void or not.

Type

boolean

$empty

$empty : boolean

Tests whether the current string is void or not.

Type

boolean

$strip

$strip : \Malenki\Bah\S

Remove white spaces surrounding the string. See \Malenki\Bah\S::strip() for more actions.

Type

\Malenki\Bah\S

$lstrip

$lstrip : \Malenki\Bah\S

Remove white spaces at the left of the string. See \Malenki\Bah\S::lstrip() for more actions.

Type

\Malenki\Bah\S

$rstrip

$rstrip : \Malenki\Bah\S

Remove white spaces at the right of the string. See \Malenki\Bah\S::rstrip() for more actions.

Type

\Malenki\Bah\S

$trim

$trim : \Malenki\Bah\S

Remove white spaces surrounding the string. Alias of \Malenki\Bah\S::strip().

Type

\Malenki\Bah\S

$ltrim

$ltrim : \Malenki\Bah\S

Remove white spaces at the left of the string. Alias of \Malenki\Bah\S::lstrip().

Type

\Malenki\Bah\S

$rtrim

$rtrim : \Malenki\Bah\S

Remove white spaces at the right of the string. Alias of \Malenki\Bah\S::rstrip().

Type

\Malenki\Bah\S

$sub

$sub : \Malenki\Bah\S

Take first character as string. See \Malenki\Bah\S::sub() for more actions.

Type

\Malenki\Bah\S

$chunk

$chunk : \Malenki\Bah\S

Get exploded string as collection of characters. See \Malenki\Bah\S::chunk() for more actions.

Type

\Malenki\Bah\S

$delete

$delete : \Malenki\Bah\S

Remove first character. See \Malenki\Bah\S::delete() for more actions.

Type

\Malenki\Bah\S

$remove

$remove : \Malenki\Bah\S

Remove first character. See \Malenki\Bah\S::delete() for more actions.

Type

\Malenki\Bah\S

$del

$del : \Malenki\Bah\S

Remove first character. See \Malenki\Bah\S::delete() for more actions.

Type

\Malenki\Bah\S

$rm

$rm : \Malenki\Bah\S

Remove first character. See \Malenki\Bah\S::delete() for more actions.

Type

\Malenki\Bah\S

$center

$center : \Malenki\Bah\S

Center the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$left

$left : \Malenki\Bah\S

Align on left the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$left_justify

$left_justify : \Malenki\Bah\S

Align on left the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$left_align

$left_align : \Malenki\Bah\S

Align on left the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$ljust

$ljust : \Malenki\Bah\S

Align on left the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$right

$right : \Malenki\Bah\S

Align on right the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$right_justify

$right_justify : \Malenki\Bah\S

Align on right the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$right_align

$right_align : \Malenki\Bah\S

Align on right the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$rjust

$rjust : \Malenki\Bah\S

Align on right the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$justify

$justify : \Malenki\Bah\S

Justify the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$just

$just : \Malenki\Bah\S

Justify the string on line having width of 79 chars.

Type

\Malenki\Bah\S

$wrap

$wrap : \Malenki\Bah\S

Get wrapped version of the string, width of 79 chars

Type

\Malenki\Bah\S

$underscore

$underscore : \Malenki\Bah\S

Get underscorized version (some_words_into_sentence)

Type

\Malenki\Bah\S

$_

$_ : \Malenki\Bah\S

Get underscorized version (some_words_into_sentence)

Type

\Malenki\Bah\S

$dash

$dash : \Malenki\Bah\S

Get dashrized version (some-words-into-sentence)

Type

\Malenki\Bah\S

$upper_camel_case

$upper_camel_case : \Malenki\Bah\S

Get lower camel case version

Type

\Malenki\Bah\S

$lower_camel_case

$lower_camel_case : \Malenki\Bah\S

Get upper camel case version

Type

\Malenki\Bah\S

$cc

$cc : \Malenki\Bah\S

Get camel case versioni (lower case for first letter)

Type

\Malenki\Bah\S

$lcc

$lcc : \Malenki\Bah\S

Get lower camel case version

Type

\Malenki\Bah\S

$ucc

$ucc : \Malenki\Bah\S

Get upper camel case version

Type

\Malenki\Bah\S

$lower

$lower : \Malenki\Bah\S

Get string into lower case

Type

\Malenki\Bah\S

$upper

$upper : \Malenki\Bah\S

Get string into upper case

Type

\Malenki\Bah\S

$first

$first : \Malenki\Bah\S

Get first character

Type

\Malenki\Bah\S

$last

$last : \Malenki\Bah\S

Get last character

Type

\Malenki\Bah\S

$title

$title : \Malenki\Bah\S

Get "title" version of the string like ucwords does

Type

\Malenki\Bah\S

$ucw

$ucw : \Malenki\Bah\S

Get upper case words

Type

\Malenki\Bah\S

$ucwords

$ucwords : \Malenki\Bah\S

Get upper case words

Type

\Malenki\Bah\S

$upper_case_words

$upper_case_words : \Malenki\Bah\S

Get upper case words

Type

\Malenki\Bah\S

$trans

$trans : \Malenki\Bah\S

Get translitterated version of the string

Type

\Malenki\Bah\S

$md5

$md5 : \Malenki\Bah\S

Get MD5 sum of the string

Type

\Malenki\Bah\S

$sha1

$sha1 : \Malenki\Bah\S

Get SHA1 sum of the string

Type

\Malenki\Bah\S

$swap_case

$swap_case : \Malenki\Bah\S

Get swapped case version

Type

\Malenki\Bah\S

$swapcase

$swapcase : \Malenki\Bah\S

Get swapped case version

Type

\Malenki\Bah\S

$swap

$swap : \Malenki\Bah\S

Get swapped case version

Type

\Malenki\Bah\S

$squeeze

$squeeze : \Malenki\Bah\S

Remove duplicates sequences of characters. See \Malenki\Bah\S::squeeze() methods to have other features

Type

\Malenki\Bah\S

$ucf

$ucf : \Malenki\Bah\S

Get upper case first

Type

\Malenki\Bah\S

$ucfirst

$ucfirst : \Malenki\Bah\S

Get upper case first

Type

\Malenki\Bah\S

$upper_case_first

$upper_case_first : \Malenki\Bah\S

Get upper case first

Type

\Malenki\Bah\S

$string

$string : string

Get current string as primitive PHP type string

Type

string

$str

$str : string

Get current string as primitive PHP type string

Type

string

$integer

$integer : integer

Get current string as primitive PHP type integer, if possible.

Type

integer

$int

$int : integer

Get current string as primitive PHP type integer, if possible.

Type

integer

$float

$float : float

Get current string as primitive PHP type float, if possible.

Type

float

$double

$double : double

Get current string as primitive PHP type double, if possible.

Type

double

$value

$value : mixed

Type

mixed — Primitive value

$col_chars

$col_chars : \Malenki\Bah\A

Stocks characters when a call is done for that.

Type

\Malenki\Bah\A

$col_bytes

$col_bytes : \Malenki\Bah\A

Stocks string's bytes.

Type

\Malenki\Bah\A

$n_length

$n_length : \Malenki\Bah\N

Stocks string's length.

Type

\Malenki\Bah\N

$int_count

$int_count : integer

Quicker access to count

Type

integer

$position

$position : integer

Current position while using methods for loop while.

Type

integer

Methods

__get()

__get(string $name) : mixed

Manage available magic getters.

By default, return internal O::$value attribute.

Parameters

string $name

Attribute’s name

Returns

mixed

__toString()

__toString() : string

Convert current object into string when this is in string context.

Returns

string

concat()

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'

Parameters

array|\Malenki\Bah\A|\Malenki\Bah\H $params

Named of set of params to use if you want use other way than multi params.

Throws

\InvalidArgumentException

If one of the arguments is not string or object having __toString() method.

Returns

\Malenki\Bah\S

__construct()

__construct(scalar $str) : void

Create new S object.

Parameters

scalar $str

Scalar value to defined as string object.

Throws

\InvalidArgumentException

If argument if not valid UTF-8 string.

getIterator()

getIterator() : \ArrayIterator

Implements the \IteratorAggregate interface

This is mandatory to allow use of foreach loop on current object. So, each item is a \Malenki\Bah\C object.

Returns

\ArrayIterator

current()

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!

Returns

\Malenki\Bah\C

key()

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!

Returns

\Malenki\Bah\N

next()

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!

Returns

\Malenki\Bah\S

rewind()

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!

Returns

\Malenki\Bah\S

valid()

valid() : boolean

Tests whether loop using fake \Iterator way is at the end or not.

The current class does not implement \Iterator interface due to conflict with \IteratorAggregate. But valid() feature is implemented with its friends!

Returns

boolean

excerpt()

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.

Parameters

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.

Throws

\InvalidArgumentException

If searched string is not string or object having __toString() method

\InvalidArgumentException

If radius is not either integer of \Malenki\Bah\N object.

Returns

\Malenki\Bah\S

squeeze()

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.

Parameters

mixed $seq

Optionnal set of characters to squeeze

Returns

\Malenki\Bah\S

strip()

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'

Parameters

mixed $str

Optionnal set of characters to strip.

mixed $type

Optionnal type of strip, left, right or both. By default strip on the two sides.

Throws

\InvalidArgumentException

If str type is not allowed

\InvalidArgumentException

If given optional type is not a string-like value.

\InvalidArgumentException

If type does not exist

Returns

\Malenki\Bah\S

lstrip()

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.

Parameters

mixed $str

Optional set of characters to strip.

Throws

\InvalidArgumentException

If str type is not allowed

Returns

\Malenki\Bah\S

rstrip()

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.

Parameters

mixed $str

Optional set of characters to strip.

Throws

\InvalidArgumentException

If str type is not allowed

Returns

\Malenki\Bah\S

trim()

trim(mixed $str, mixed $type) : \Malenki\Bah\S

Trims the string (Alias).

Parameters

mixed $str

Optionnal set of characters to strip.

mixed $type

Optionnal type of strip, left, right or both. By default strip on the two sides.

Throws

\InvalidArgumentException

If given optional type is not a string-like value.

\InvalidArgumentException

If type does not exist

\InvalidArgumentException

If str type is not allowed

Returns

\Malenki\Bah\S

ltrim()

ltrim(mixed $str) : \Malenki\Bah\S

Trims the string on the left (Alias).

Parameters

mixed $str

Optionnal set of characters to strip.

Throws

\InvalidArgumentException

If str type is not allowed

Returns

\Malenki\Bah\S

rtrim()

rtrim(mixed $str) : \Malenki\Bah\S

Trims the string on the right (Alias).

Parameters

mixed $str

Optionnal set of characters to strip.

Throws

\InvalidArgumentException

If str type is not allowed

Returns

\Malenki\Bah\S

append()

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'

Parameters

mixed $str

String-like content

Throws

\InvalidArgumentException

If given string is not… a string-like value.

Returns

\Malenki\Bah\S

after()

after(mixed $str) : \Malenki\Bah\S

Adds content after the string (Alias).

Parameters

mixed $str

A string-like value to add

Throws

\InvalidArgumentException

If given string is not… a string-like value.

Returns

\Malenki\Bah\S

prepend()

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 !'

Parameters

mixed $str

String-like content

Throws

\InvalidArgumentException

If given string is not… a string-like value.

Returns

\Malenki\Bah\S

before()

before(mixed $str) : \Malenki\Bah\S

Adds content before the string.

Parameters

mixed $str

String-like content

Throws

\InvalidArgumentException

If given string is not… a string-like value.

Returns

\Malenki\Bah\S

surround()

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)'

Parameters

mixed $before

String-like starting string

mixed $after

String-like ending string

Throws

\InvalidArgumentException

If starting or ending string is not string-like value.

Returns

\Malenki\Bah\S

insert()

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'

Parameters

mixed $str

String-like content

mixed $pos

Integer-like content (integer or \Malenki\Bah\N object)

Throws

\InvalidArgumentException

If given string is not valid

\InvalidArgumentException

If given position is not valid.

Returns

\Malenki\Bah\S

put()

put(mixed $str, mixed $pos) : \Malenki\Bah\S

Inserts new content at given position (Alias).

Parameters

mixed $str

String-like content

mixed $pos

Integer-like content

Throws

\InvalidArgumentException

If given string is not valid

\InvalidArgumentException

If given position is not valid.

Returns

\Malenki\Bah\S

camelCase()

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.

Parameters

boolean $is_upper

true to have upper camel case, false to have lower camel case. Optional.

Returns

\Malenki\Bah\S

lowerCamelCase()

lowerCamelCase() : \Malenki\Bah\S

Gets string converted in lower camel case.

This is an alias of \Malenki\Bah\S::camelCase().

Returns

\Malenki\Bah\S

upperCamelCase()

upperCamelCase() : \Malenki\Bah\S

Gets string converted in upper camel case.

This is an alias of \Malenki\Bah\S::camelCase()true.

Returns

\Malenki\Bah\S

sub()

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'

Parameters

mixed $offset

Where to start the substring, 0 by default, as N or

                 integer
mixed $limit

Size of the substring, 1 by default, as N or

                 integer

Throws

\InvalidArgumentException

If offset is not an Integer-like

\InvalidArgumentException

If offset is not valid

\InvalidArgumentException

If limit is not an Integer-like

\InvalidArgumentException

If limit is negative

Returns

\Malenki\Bah\S

position()

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

Parameters

mixed $needle

The searched string-like content

Throws

\InvalidArgumentException

If needle is not a string-like value

\InvalidArgumentException

If needle is empty

Returns

\Malenki\Bah\A

pos()

pos(mixed $needle) : \Malenki\Bah\A

Gets all available positions of given string needle (Alias).

Parameters

mixed $needle

The searched string-like content

Throws

\InvalidArgumentException

If needle is not a string-like value

\InvalidArgumentException

If needle is empty

Returns

\Malenki\Bah\A

delete()

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…'

Parameters

integer|\Malenki\Bah\N $offset

Integer-like offset

integer|\Malenki\Bah\N $limit

Integer-like limit size

Throws

\InvalidArgumentException

If offset is not an integer-like

\InvalidArgumentException

If offset is negative

\InvalidArgumentException

If limite is not an integer-like

Returns

\Malenki\Bah\S

del()

del(mixed $offset, mixed $limit) : \Malenki\Bah\S

Removes string part using offset and limit size (Alias).

Parameters

mixed $offset

Integer-like offset

mixed $limit

Integer-like limit size

Throws

\InvalidArgumentException

If offset is not an integer-like

\InvalidArgumentException

If offset is negative

\InvalidArgumentException

If limite is not an integer-like

Returns

\Malenki\Bah\S

remove()

remove(mixed $offset, mixed $limit) : \Malenki\Bah\S

Removes string part using offset and limit size (Alias).

Parameters

mixed $offset

Integer-like offset

mixed $limit

Integer-like limit size

Throws

\InvalidArgumentException

If offset is not an integer-like

\InvalidArgumentException

If offset is negative

\InvalidArgumentException

If limite is not an integer-like

Returns

\Malenki\Bah\S

rm()

rm(mixed $offset, mixed $limit) : \Malenki\Bah\S

Removes string part using offset and limit size (Alias).

Parameters

mixed $offset

Integer-like offset

mixed $limit

Integer-like limit size

Throws

\InvalidArgumentException

If offset is not an integer-like

\InvalidArgumentException

If offset is negative

\InvalidArgumentException

If limite is not an integer-like

Returns

\Malenki\Bah\S

startsWith()

startsWith(mixed $str) : boolean

Checks that current string starts with the given string or not

Parameters

mixed $str

primitive string or object havin __toString method

Throws

\InvalidArgumentException

If str is not string-like value

Returns

boolean

endsWith()

endsWith(mixed $str) : boolean

Checks that current string ends with the given string or not

Parameters

mixed $str

primitive string or object havin __toString method

Throws

\InvalidArgumentException

If str is not string-like value

Returns

boolean

match()

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

Parameters

mixed $expr

primitive string or object having __toString method

Throws

\InvalidArgumentException

If regexp pattern is not a string-like value.

Returns

boolean

regexp()

regexp(mixed $expr) : boolean

Alias of match method

Parameters

mixed $expr

primitive string or object having __toString method

Throws

\InvalidArgumentException

If regexp pattern is not a string-like value.

Returns

boolean

re()

re(mixed $expr) : boolean

Alias of match method

Parameters

mixed $expr

primitive string or object having __toString method

Throws

\InvalidArgumentException

If regexp pattern is not a string-like value.

Returns

boolean

test()

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

Parameters

mixed $str

A string-like to test

Throws

\InvalidArgumentException

If argument is not a string-like or a scalar.

Returns

boolean

title()

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 !'

Parameters

mixed $sep

Optionnal sequence of additionnal separators.

Throws

\InvalidArgumentException

If not null sep has not right type or contains bad type.

Returns

\Malenki\Bah\S

ucw()

ucw(mixed $sep) : \Malenki\Bah\S

Converts the string to upper case words (Alias).

Parameters

mixed $sep

Optionnal sequence of additionnal separators.

Throws

\InvalidArgumentException

If not null sep has not right type or contains bad type.

Returns

\Malenki\Bah\S

ucwords()

ucwords(mixed $sep) : \Malenki\Bah\S

Converts the string to upper case words (Alias).

Parameters

mixed $sep

Optionnal sequence of additionnal separators.

Throws

\InvalidArgumentException

If not null sep has not right type or contains bad type.

Returns

\Malenki\Bah\S

upperCaseWords()

upperCaseWords(mixed $sep) : \Malenki\Bah\S

Converts the string to upper case words (Alias).

Parameters

mixed $sep

Optionnal sequence of additionnal separators.

Throws

\InvalidArgumentException

If not null sep has not right type or contains bad type.

Returns

\Malenki\Bah\S

charAt()

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'

Parameters

integer|\Malenki\Bah\N $idx

The index where the character is, as N or integer.

Throws

\InvalidArgumentException

If index is not an integer-like.

\InvalidArgumentException

If index does not exist.

Returns

\Malenki\Bah\C

take()

take(integer|\Malenki\Bah\N $idx) : \Malenki\Bah\C

Alias of charAt() method

Parameters

integer|\Malenki\Bah\N $idx

Position as integer-like

Returns

\Malenki\Bah\C

at()

at(integer|\Malenki\Bah\N $idx) : \Malenki\Bah\C

Alias of charAt() method

Parameters

integer|\Malenki\Bah\N $idx

Position as integer-like

Returns

\Malenki\Bah\C

count()

count() : integer

Implements Countable interface.

Note: This method does not returns an \Malenki\Bah\N object, but a primitive integer, to have same behaviour as its interface definition.

Returns

integer

times()

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)

Parameters

mixed $n

Integer-like value

Throws

\InvalidArgumentException

If N is not an integer-like.

\InvalidArgumentException

If N is negative

Returns

\Malenki\Bah\S

repeat()

repeat(mixed $n) : \Malenki\Bah\S

Repeats N times current string (Alias).

Parameters

mixed $n

Integer-like value

Throws

\InvalidArgumentException

If N is not an integer-like.

\InvalidArgumentException

If N is negative

Returns

\Malenki\Bah\S

wrap()

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é.

Parameters

integer|\Malenki\Bah\N $width

Width the text must have

mixed $cut

Optional string to put at each linebreak, as

                 string-like

Throws

\InvalidArgumentException

If width is not an integer-like

\InvalidArgumentException

If cut is not a string-like

Returns

\Malenki\Bah\S

margin()

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é.

Parameters

mixed $left

Margin left (N or integer)

mixed $right

Margin right, optional (N or integer)

mixed $alinea

First line, optional (N or integer)

Throws

\InvalidArgumentException

If margin left, margin right or alinea is not an integer-like.

\InvalidArgumentException

If margin left and/or right are negative

\InvalidArgumentException

If alinea is greater than margin left

Returns

\Malenki\Bah\S

center()

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é.

Parameters

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 PHP_EOL.

Throws

\InvalidArgumentException

If width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

left()

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.

Parameters

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 PHP_EOL.

Throws

\InvalidArgumentException

If Width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

ljust()

ljust(mixed $width, mixed $cut) : \Malenki\Bah\S

Left aligns text to fit it into the given width (alias).

Parameters

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 PHP_EOL.

Throws

\InvalidArgumentException

If Width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

leftAlign()

leftAlign(mixed $width, mixed $cut) : \Malenki\Bah\S

Left aligns text to fit it into the given width (alias).

Parameters

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 PHP_EOL.

Throws

\InvalidArgumentException

If Width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

leftJustify()

leftJustify(mixed $width, mixed $cut) : \Malenki\Bah\S

Left aligns text to fit it into the given width (alias).

Parameters

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 PHP_EOL.

Throws

\InvalidArgumentException

If Width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

right()

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é.

Parameters

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 PHP_EOL.

Throws

\InvalidArgumentException

If Width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

rjust()

rjust(mixed $width, mixed $cut) : \Malenki\Bah\S

Right aligns text to fit it into the given width (alias).

Parameters

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 PHP_EOL.

Throws

\InvalidArgumentException

If Width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

rightAlign()

rightAlign(mixed $width, mixed $cut) : \Malenki\Bah\S

Right aligns text to fit it into the given width (alias).

Parameters

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 PHP_EOL.

Throws

\InvalidArgumentException

If Width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

rightJustify()

rightJustify(mixed $width, mixed $cut) : \Malenki\Bah\S

Right aligns text to fit it into the given width (alias).

Parameters

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 PHP_EOL.

Throws

\InvalidArgumentException

If Width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

justify()

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é.

Parameters

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 left

mixed $cut

End of line string-like. Optional, set by default at PHP_EOL

Throws

\InvalidArgumentException

If given type is not left or right.

\InvalidArgumentException

If width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

explode()

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'

Parameters

mixed $sep

String-like regex

Throws

\InvalidArgumentException

Regexp is void

Returns

\Malenki\Bah\A

split()

split(mixed $sep) : \Malenki\Bah\A

Splits the string using Regexp.

Parameters

mixed $sep

String-like regex

Throws

\InvalidArgumentException

Regexp is void

Returns

\Malenki\Bah\A

cut()

cut(mixed $sep) : \Malenki\Bah\A

Splits the string using Regexp.

Parameters

mixed $sep

String-like regex

Throws

\InvalidArgumentException

Regexp is void

Returns

\Malenki\Bah\A

chunk()

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'

Parameters

integer|\Malenki\Bah\N $size

If not given, its default value is 1.

Throws

\InvalidArgumentException

If size is not an integer-like.

\InvalidArgumentException

If chunk's size is less than one.

Returns

\Malenki\Bah\A

replace()

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.

Parameters

mixed $pattern

Pattern to match. A string-like type.

mixed $string

String to put in place of matching parts.

Throws

\InvalidArgumentException

If one of the arguments is not a string-like type.

Returns

\Malenki\Bah\S

change()

change(mixed $pattern, mixed $string) : \Malenki\Bah\S

Change matching parts of the string using Regexp (Alias).

Parameters

mixed $pattern

Pattern to match. A string-like type.

mixed $string

String to put in place of matching parts.

Throws

\InvalidArgumentException

If one of the arguments is not a string-like type.

Returns

\Malenki\Bah\S

format()

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'

Parameters

array|\Malenki\Bah\A|\Malenki\Bah\H $params

Named of set of params to use if you want use other way than multi params.

Throws

\InvalidArgumentException

If at least one argument is not a scalar or an object having __toString() method.

Returns

\Malenki\Bah\S

sprintf()

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).

Parameters

array|\Malenki\Bah\A|\Malenki\Bah\H $params

Named of set of params to use if you want use other way than multi params.

Throws

\InvalidArgumentException

If at least one argument is not a scalar or an object having __toString() method.

Returns

\Malenki\Bah\S

fmt()

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).

Parameters

array|\Malenki\Bah\A|\Malenki\Bah\H $params

Named of set of params to use if you want use other way than multi params.

Throws

\InvalidArgumentException

If at least one argument is not a scalar or an object having __toString() method.

Returns

\Malenki\Bah\S

set()

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

Parameters

integer|\Malenki\Bah\N $idx

Index of an existing position, as integer-like

mixed $char

New character to set, as string-like.

Throws

\InvalidArgumentException

If index is not an integer-like.

\RuntimeException

If index does not exist.

\InvalidArgumentException

If New character is not a string-like type.

\InvalidArgumentException

If new character is not a string-like having a size of one.

Returns

\Malenki\Bah\S

detab()

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'

Parameters

mixed $n

An integer-like value for tab size.

string $eol

Optionnal parameter to set default EOL to use.

Throws

\InvalidArgumentException

If tab's size is no integer-like value

\InvalidArgumentException

If tab's size is equal to or inférior to zero

Returns

\Malenki\Bah\S

untag()

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>'

Parameters

mixed $tag

Tag(s) to keep

Throws

\InvalidArgumentException

If invalid type is used.

Returns

\Malenki\Bah\S

stripTags()

stripTags(mixed $tag) : \Malenki\Bah\S

Removes HTML and XML tags (Alias).

Parameters

mixed $tag

Tag(s) to keep

Throws

\InvalidArgumentException

If invalid type is used.

Returns

\Malenki\Bah\S

n()

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"

Parameters

boolean $after

If false, put new line before the string

Returns

\Malenki\Bah\S

r()

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"

Parameters

boolean $after

If false, put new line before the string

Returns

\Malenki\Bah\S

eof()

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"

Parameters

boolean $after

If false, put new line before the string

Returns

\Malenki\Bah\S

rn()

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"

Parameters

boolean $after

If false, put new line before the string

Returns

\Malenki\Bah\S

mustBeStringOrScalar()

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.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeString()

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.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeInteger()

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.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeFloat()

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.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeDouble()

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.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeNumeric()

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.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeArray()

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.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeHash()

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.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeArrayOrHash()

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.

Parameters

mixed $arg

The value to test.

string $arg_name

Optional name of the value, used into exception’s message.

Throws

\InvalidArgumentException

If value’s type is not valid

mustBeCallable()

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.

Parameters

mixed $arg

The value to test

mixed $arg_name

Optional name of the value, used into error message

Throws

\InvalidArgumentException

If arg is not callable

_chars()

_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

Returns

\Malenki\Bah\A

_bytes()

_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

Returns

\Malenki\Bah\A

_length()

_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.

Returns

\Malenki\Bah\A

_to()

_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.

Parameters

string $name

Either to_c or to_n

Throws

\RuntimeException

If you try converting to \Malenki\Bah\C object a string having more than one character.

\RuntimeException

If you try cinverting string having not numeric value to \Malenki\Bah\N object.

Returns

\Malenki\Bah\C|\Malenki\Bah\N

_string()

_string() : string

Converts current string object to string php primitive type.

This is runtime part of magic getter \Malenki\Bah\S::$string.

Returns

string

_str()

_str() : string

Converts current string object to string php primitive type (Alias).

This is runtime part of magic getter \Malenki\Bah\S::$str.

Returns

string

_integer()

_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

Throws

\RuntimeException

If current string has not numeric value.

Returns

integer

_int()

_int() : integer

Converts current string object to integer primitive type.

This runtime for magic getter is the shorter version of \Malenki\Bah\S::$integer magic getter.

Throws

\RuntimeException

If current string has not numeric value.

Returns

integer

_float()

_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

Throws

\RuntimeException

If current string has not numeric value.

Returns

integer

_double()

_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

Throws

\RuntimeException

If current string has not numeric value.

Returns

integer

_trans()

_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+

Throws

\RuntimeException

If this is called and intl extension is not installed.

\RuntimeException

If intl extension is installed but that uses PHP version prior to 5.4.0.

Returns

\Malenki\Bah\S

_slug()

_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.

Throws

\RuntimeException

If this is called and intl extension is not installed.

\RuntimeException

If intl extension is installed but that uses PHP version prior to 5.4.0.

Returns

\Malenki\Bah\S

_swapCase()

_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'

Returns

\Malenki\Bah\S

_underscore()

_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'

Returns

\Malenki\Bah\S

_dash()

_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'

Returns

\Malenki\Bah\S

_first()

_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

Returns

\Malenki\Bah\S

_last()

_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

Returns

\Malenki\Bah\S

_upperCaseFirst()

_upperCaseFirst() : \Malenki\Bah\S

Converts to upper case first.

Converts the first character to upper case.

Returns

\Malenki\Bah\S

_isVoid()

_isVoid() : boolean

Test whether the current string is void or not.

This is runtime part of some magic getters.

Examples:

$s = new S('foo');
var_dump($s->void); // false

$s = new S('');
var_dump($s->void); // true

Returns

boolean

_upper()

_upper() : \Malenki\Bah\S

Returns new string object converted to uppercase.

Returns

\Malenki\Bah\S

_lower()

_lower() : \Malenki\Bah\S

Returns new string object converted to lowercase.

Returns

\Malenki\Bah\S

_leftOrRightJustify()

_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…)

Parameters

string $type

Must be either left or right

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 PHP_EOL.

Throws

\InvalidArgumentException

If given type is not left or right.

\InvalidArgumentException

If width is not an integer-like.

\InvalidArgumentException

If width is negative or null.

\InvalidArgumentException

If cut end of line string is not string-like.

Returns

\Malenki\Bah\S

_rtl()

_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

Returns

boolean

_ltr()

_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

Returns

boolean

_hasMixedDirection()

_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

Returns

boolean

_zorg()

_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 !'

Returns

\Malenki\Bah\S

_md5()

_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'

Returns

\Malenki\Bah\S

_sha1()

_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'

Returns

\Malenki\Bah\S

_formatEngine()

_formatEngine(mixed $args) : \Malenki\Bah\S

_formatEngine

Parameters

mixed $args

Returns

\Malenki\Bah\S

_nl()

_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.

Parameters

string $type

One of this string: \n, \r, \r\n or PHP_EOL.

boolean $after

Set to false to put new line before rather than after as default.

Returns

\Malenki\Bah\S