PHP code example of malenki / bah

1. Go to this page and download the library: Download malenki/bah library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

malenki / bah example snippets


$greek = new S('Τα ελληνικά σου είναι καλύτερα απο τα Γαλλικά μου!');

echo $greek; // 'Τα ελληνικά σου είναι καλύτερα απο τα Γαλλικά μου!'

echo $greek->upper; // ΤΑ ΕΛΛΗΝΙΚΆ ΣΟΥ ΕΊΝΑΙ ΚΑΛΎΤΕΡΑ ΑΠΟ ΤΑ ΓΑΛΛΙΚΆ ΜΟΥ!

echo $greek->lower; // τα ελληνικά σου είναι καλύτερα απο τα γαλλικά μου!

echo $greek->title; // Τα Ελληνικά Σου Είναι Καλύτερα Απο Τα Γαλλικά Μου!

echo $greek->title->swap; // τΑ εΛΛΗΝΙΚΆ σΟΥ εΊΝΑΙ κΑΛΎΤΕΡΑ αΠΟ τΑ γΑΛΛΙΚΆ μΟΥ!

echo $greek->length; // 50

echo $greek->lcc; // ταΕλληνικάΣουΕίναιΚαλύτεραΑποΤαΓαλλικάΜου

echo $greek->ucc; // ΤαΕλληνικάΣουΕίναιΚαλύτεραΑποΤαΓαλλικάΜου

echo $greek->dash; // τα-ελληνικά-σου-είναι-καλύτερα-απο-τα-γαλλικά-μου

echo $greek->underscore; // τα_ελληνικά_σου_είναι_καλύτερα_απο_τα_γαλλικά_μου

$greek->trans; // Ta ellenika sou einai kalytera apo ta Gallika mou!

echo $greek->lcc->trans; // taEllenikaSouEinaiKalyteraApoTaGallikaMou 

echo $greek->first; // Τ

echo $greek->last; // !

$s = new S('azzertyy');
echo $s->squeeze; // azerty

$s = new S('aaazzertyy');
echo $s->squeeze('za'); // azertyy

echo $greek->sub(4)->n;

echo $greek->chars->length->to_s->n;

echo $greek->bytes->length->to_s->n;

$long = new S('Put a very long string here…');
echo $long->wrap(20)->n->n;
echo $long->wrap(30)->n->n;
echo $long->wrap(40)->n->n;
echo $long->wrap(80)->n->n;
echo $long->wrap(80)->ucw->n->n; // with upper case words
echo 'First: ';
// margin left 10 chars length, right 0, first -7 to place the previous string "First: "
echo $long->wrap(40)->margin(10, 0, -7)->n->n;
echo $long->wrap(40)->margin(10)->n->n; // same as previous, but only left margin

$s = new S('Τα ελληνικά σου είναι καλύτερα απο τα Γαλλικά μου!');
echo $s->trans->n; // Ta ellenika sou einai kalytera apo ta Gallika mou!

$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

$s = new S('Ceci est du français tout à fait banal.');
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

$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

$s = new S('Foo');
echo $s->tag('p strong.bar'); // '<p><strong class="bar">Foo</strong></p>'

$c = new C("€");
while($c->bytes->valid())
{
    // for each bytes, print it as binary string and add new line
    echo $c->bytes->current()->b->n;
    $c->bytes->next();
}

$c = new C("Œ");
echo $c->family->join(', ');
/*
Ā, ā, Ă, ă, Ą, ą, Ć, ć, Ĉ, ĉ, Ċ, ċ, Č, č, Ď, ď, Đ, đ, Ē, ē,
Ĕ, ĕ, Ė, ė, Ę, ę, Ě, ě, Ĝ, ĝ, Ğ, ğ, Ġ, ġ, Ģ, ģ, Ĥ, ĥ, Ħ, ħ,
Ĩ, ĩ, Ī, ī, Ĭ, ĭ, Į, į, İ, ı, IJ, ij, Ĵ, ĵ, Ķ, ķ, ĸ, Ĺ, ĺ, Ļ,
ļ, Ľ, ľ, Ŀ, ŀ, Ł, ł, Ń, ń, Ņ, ņ, Ň, ň, ʼn, Ŋ, ŋ, Ō, ō, Ŏ, ŏ,
Ő, ő, Œ, œ, Ŕ, ŕ, Ŗ, ŗ, Ř, ř, Ś, ś, Ŝ, ŝ, Ş, ş, Š, š, Ţ, ţ,
Ť, ť, Ŧ, ŧ, Ũ, ũ, Ū, ū, Ŭ, ŭ, Ů, ů, Ű, ű, Ų, ų, Ŵ, ŵ, Ŷ, ŷ,
Ÿ, Ź, ź, Ż, ż, Ž, ž, ſ
*/

$c = new C("Œ");
echo $c->block; // Latin Extended-A

$s = new C('λ');
echo $C->trans; // "l"

$c = new C('ش');
var_dump($c->rtl); // true
var_dump($c->is_rtl); // true
var_dump($c->is_right_to_left); // true
var_dump($c->right_to_left); // true
var_dump($c->ltr); // false
var_dump($c->is_ltr); // false
var_dump($c->is_left_to_right); // false
var_dump($c->left_to_right); // false

$a = new A(array('un', 'deux', 'trois', 'quatre'));
var_dump(count($a));
var_dump($a->last_but_one);

$a = new A(array('zéro', 'un', 'deux', 'trois', 'quatre'));
echo $a->take(2); // 'deux'
// or
echo $a->index_2;
// or
echo $a->key_2;

$a = new A(array('un', 'deux', 'trois', 'quatre'));
var_dump($a->shuffle); //randomize
var_dump($a->sort); //sort ascendently
var_dump($a->reverse); //reverse order
var_dump($a->sort->reverse); // sort and then reverse it

$a = new A(array('foo', 'bar', 'thing', 'other'));
$a->find('>= 2'); // has 'thing' and 'other'
$a->find('odd'); // has 'bar' and 'other'

$a = new A(array('un', 'deux', 'trois', 'quatre'));
var_dump($a->random);
// or
var_dump($a->random(1));

$a = new A(array('un', 'deux', 'trois', 'quatre'));
var_dump($a->random(2));

$a = new A(array('un', 'deux', 'trois', 'quatre'));
var_dump($a->join);
//or
var_dump($a->implode);

$a = new A(array('un', 'deux', 'trois', 'quatre'));
var_dump($a->join(', '));
//or
var_dump($a->implode(', '));

$a = new A(array('un', 'deux', 'trois', 'quatre'));

while($a->valid) // you can use method call too
{
    echo $a->current . "\n";
    $a->next;
}

$five = new N(5);
$two = new N(2);

echo $five->plus(2); // native number or N object
echo $five->minus($two);
echo $five->divide(2);

$five = new N(5);
$two = new N(2);

var_dump($two->minus($five)->negative); //should be true
var_dump($two->minus(2)->zero); //should be true
var_dump($two->positive); //should be true

$n = new N(1979);

echo $n->base(2); // get "11110111011"
echo $n->base(3); // get "2201022"
echo $n->base(34); // get "1o7"

$n = new N(1979);

// binary
echo $n->bin;
// or
echo $n->b;

// octal
echo $n->oct;
// or
echo $n->o;

// hexadecimal
echo $n->hex;
// or
echo $n->h;



$n = new N(3);
var_dump($n->odd);
var_dump($n->even);
$n = new N(4);
var_dump($n->odd);
var_dump($n->even);

$n = new N(5);
var_dump($n->gt(3)); // true
var_dump($n->lt(3)); // false
var_dump($n->eq(5)); // true
var_dump($n->neq(3)); // true
var_dump($n->test('>= 3')); // true

$n = new N(4.3);
var_dump($n->decimal); // N object having 0.3 as value

$five = new N(5);

print($five->roman);
print($five->greek);

$n = new N(123456); // will be '十二兆三千四百五十六'
echo $n->chinese();
// or
echo $n->chinese;
// or
echo $n->mandarin;
// or
echo $n->putonghua;

$n = new N(16.98); // Will be '十六点九八'
echo $n->chinese;

$n = new N(-16.98); // Will be '负十六点九八'
echo $n->chinese;

$n = new N(208);
echo  $n->chinese(true); // Will be '二百〇八'
echo  $n->chinese_other_zero; // Will be '二百〇八'
echo  $n->mandarin_other_zero; // Will be '二百〇八'
echo  $n->putonghua_other_zero; // Will be '二百〇八'
// but:
echo  $n->chinese(); // Will be '二百零八'
echo  $n->chinese; // Will be '二百零八'
echo  $n->mandarin; // Will be '二百零八'
echo  $n->putonghua; // Will be '二百零八'

$h = new H();
$h->set('my_key', 'My Value');
// or
$y->my_key = 'My Value';

$h->get('my_key'); // 'My Value'
// or
echo $h->my_key; // 'My Value'

$h->delete('my_key');
// or
unset($h->my_key);

$h = new H(array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4));

while($h->valid)
{
    printf(
        "key: %s => value: %d\n",
        $h->current->key,
        $h->current->value
    );
    $h->next;
}

$h = new H(array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4));

$arr = $h->find('/[o]+/');
var_dump($arr); // array('one' => 1, 'two' => 2, 'four' => 4)

$s = new S('This is a string');
var_dump($s->length); // object N
var_dump($s->length->int); // integer