public function runJphp() { $str1 = 'foobar'; $len = Str::length($str1); $pos = Str::pos($str1, 'oba'); $pos = Str::pos($str1, 'oba', 4); $upper = Str::upper($str1); $replace = Str::replace($str1, 'o', 'O'); }
--TEST-- php\lib\str Test - comparing --FILE-- <?php use php\lib\Str as str; echo "equalsIgnoreCase(foo, foo) == " . str::equalsIgnoreCase('foo', 'foo'), "\n"; echo "equalsIgnoreCase(foo, fOO) == " . str::equalsIgnoreCase('foo', 'fOO'), "\n"; echo "equalsIgnoreCase(Foo, foo) == " . str::equalsIgnoreCase('Foo', 'foo'), "\n"; echo "--compare\n"; echo "compare(foo, foo) == " . str::compare('foo', 'foo'), "\n"; echo "compare(Foo, foo) == " . str::compare('Foo', 'foo'), "\n"; echo "compare(foo, Foo) == " . str::compare('foo', 'Foo'), "\n"; echo "--compare-ignore-case\n"; echo "compareIgnoreCase(foo, foo) == " . str::compareIgnoreCase('foo', 'foo'), "\n"; echo "compareIgnoreCase(Foo, foo) == " . str::compareIgnoreCase('Foo', 'foo'), "\n"; echo "compareIgnoreCase(foo, Foo) == " . str::compareIgnoreCase('foo', 'Foo'), "\n"; ?> --EXPECT-- equalsIgnoreCase(foo, foo) == 1 equalsIgnoreCase(foo, fOO) == 1 equalsIgnoreCase(Foo, foo) == 1 --compare compare(foo, foo) == 0 compare(Foo, foo) == -32 compare(foo, Foo) == 32 --compare-ignore-case compareIgnoreCase(foo, foo) == 0 compareIgnoreCase(Foo, foo) == 0 compareIgnoreCase(foo, Foo) == 0
--FILE-- <?php use php\lib\Str as str; echo "length(foobar) == " . str::length('foobar'), "\n"; echo "lower(FOObar) == " . str::lower('FOObar'), "\n"; echo "upper(FOObar) == " . str::upper('FOObar'), "\n"; echo "lowerFirst(FOObar) == " . str::lowerFirst('FOObar'), "\n"; echo "upperFirst(fOObar) == " . str::upperFirst('fOObar'), "\n"; echo "repeat(foo, 3) == " . str::repeat('foo', 3), "\n"; echo "repeat(o, 6) == " . str::repeat('o', 6), "\n"; echo "repeat(o, -1) == " . str::repeat('o', -1), "*nothing*\n"; echo "reverse(foobar) == " . str::reverse('foobar'), "\n"; echo "sub(foobar, 3) == " . str::sub('foobar', 3), "\n"; echo "sub(foobar, 3, 5) == " . str::sub('foobar', 3, 5), "\n"; echo "trim( foobar ) == " . str::trim(' foobar '), "\n"; echo "format(f[%s]r, ooba) == " . str::format('f[%s]r', 'ooba'), "\n"; ?> --EXPECT-- length(foobar) == 6 lower(FOObar) == foobar upper(FOObar) == FOOBAR lowerFirst(FOObar) == fOObar upperFirst(fOObar) == FOObar repeat(foo, 3) == foofoofoo repeat(o, 6) == oooooo repeat(o, -1) == *nothing* reverse(foobar) == raboof sub(foobar, 3) == bar sub(foobar, 3, 5) == ba trim( foobar ) == foobar format(f[%s]r, ooba) == f[ooba]r
--TEST-- php\lib\str Test - isLower, isUpper, lower, upper --FILE-- <?php use php\lib\Str as str; var_dump(str::isLower('моя строка')); var_dump(str::isLower('Моя строка')); var_dump(str::isLower('')); var_dump(str::isUpper('МОЯ СТРОКА')); var_dump(str::isUpper('мОЯ СТРОКА')); var_dump(str::isUpper('')); var_dump(str::isUpper(' $ % 467')); var_dump(str::isLower(' $ % 467')); var_dump(str::upper('мОя СтрОка')); var_dump(str::lower('мОя СтрОка')); ?> --EXPECT-- bool(true) bool(false) bool(false) bool(true) bool(false) bool(false) bool(false) bool(false) string(10) "МОЯ СТРОКА" string(10) "моя строка"
--TEST-- php\lib\str Test - isNumber --FILE-- <?php use php\lib\Str as str; var_dump(str::isNumber('012738')); var_dump(str::isNumber('9999999999999999999999999999999999999999999999')); var_dump(str::isNumber('9999999999999999999999999999999999999999999999', false)); var_dump(str::isNumber('0.12738')); var_dump(str::isNumber('0,12738')); var_dump(str::isNumber('1234 ')); var_dump(str::isNumber(' 1234')); var_dump(str::isNumber('0x16')); ?> --EXPECT-- bool(true) bool(true) bool(false) bool(false) bool(false) bool(false) bool(false) bool(false)
<?php use php\lib\Str as str; echo "--test-split\n"; echo "split('f,o,o,b,a,r', ',') == "; var_dump(str::split('f,o,o,b,a,r', ',')); echo "split('f,o,o,b,a,r', ',', 3) == "; var_dump(str::split('f,o,o,b,a,r', ',', 3)); echo "split('foobar', ',', 3) == "; var_dump(str::split('foobar', ',', 3)); echo "split('foo,,bar', ',') == "; var_dump(str::split('foo,,bar', ',')); echo "split('foo,,bar', ',,') == "; var_dump(str::split('foo,,bar', ',,')); echo "--test-join\n"; echo "join([foo,bar], ',') == " . str::join(['foo', 'bar'], ','), "\n"; echo "join([foo,bar], ',,') == " . str::join(['foo', 'bar'], ',,'), "\n"; ?> --EXPECT-- --test-split split('f,o,o,b,a,r', ',') == array(6) { [0]=> string(1) "f" [1]=> string(1) "o" [2]=> string(1) "o" [3]=> string(1) "b" [4]=> string(1) "a" [5]=>
--TEST-- php\lib\str Test - leng --FILE-- <?php use php\lib\Str as str; $random = str::random(); var_dump($random); $random = str::random(8); var_dump($random); var_dump(str::random() != str::random()); $random = str::random(8, '1234567890'); var_dump($random); var_dump(str::isNumber($random)); ?> --EXPECTF-- string(16) "%s string(8) "%s bool(true) string(8) "%s bool(true)
echo "lastPos(ob_foobar, ob, -1000) == " . str::lastPos('ob_foobar', 'ob', -1000), "\n"; echo "--last-pos-ignore-case\n"; echo "lastPosIgnoreCase(ob_foObar, ob) == " . str::lastPosIgnoreCase('ob_foObar', 'ob'), "\n"; echo "lastPosIgnoreCase(ob_foObar, ob, 4) == " . str::lastPosIgnoreCase('ob_foObar', 'ob', 7), "\n"; echo "lastPosIgnoreCase(ob_foObar, ob, 100) == " . str::lastPosIgnoreCase('ob_foObar', 'ob', 100), "\n"; echo "lastPosIgnoreCase(ob_foObar, ob, -1) == " . str::lastPosIgnoreCase('ob_foObar', 'ob', -1), "\n"; echo "lastPosIgnoreCase(ob_foObar, ob, -1000) == " . str::lastPosIgnoreCase('ob_foObar', 'ob', -1000), "\n"; echo "--contains\n"; echo "contains(foobar, ob) == " . (str::contains('foobar', 'ob') ? "1" : "0"), "\n"; echo "contains(foobar, OB) == " . (str::contains('foobar', 'OB') ? "1" : "0"), "\n"; echo "--count\n"; echo "count(foobar, o) == " . str::count('foobar', 'o'), "\n"; echo "count(foobar, o, 2) == " . str::count('foobar', 'o', 2), "\n"; echo "count(foobar, oo) == " . str::count('foobar', 'oo'), "\n"; echo "count(foobar, oo, 2) == " . str::count('foobar', 'oo', 2), "\n"; echo "count(foobar, O) == " . str::count('foobar', 'O'), "\n"; ?> --EXPECT-- pos(Ob_foobar, ob) == 5 pos(Ob_foobar, ob, 4) == -1 pos(Ob_foobar, ob, 100) == -1 pos(Ob_foobar, ob, -1) == 5 pos(Ob_foobar, ob, -1000) == 5 --ignore-case posIgnoreCase(Ob_foobar, ob) == 0 posIgnoreCase(Ob_foobar, ob, 4) == -1 posIgnoreCase(Ob_foobar, ob, 100) == -1 posIgnoreCase(Ob_foobar, ob, -1) == 0 posIgnoreCase(Ob_foobar, ob, -1000) == 0 --last-pos lastPos(ob_foobar, ob) == 5