Пример #1
0
--TEST--
php\lib\str Test - comparing
--FILE--
<?php 
use php\lib\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
Пример #2
0
<?php 
use php\lib\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]=>
Пример #3
0
echo "posIgnoreCase(Ob_foobar, ob, 4) == " . str::posIgnoreCase('Ob_foobar', 'ob', 7), "\n";
echo "posIgnoreCase(Ob_foobar, ob, 100) == " . str::posIgnoreCase('Ob_foobar', 'ob', 100), "\n";
echo "posIgnoreCase(Ob_foobar, ob, -1) == " . str::posIgnoreCase('Ob_foobar', 'ob', -1), "\n";
echo "posIgnoreCase(Ob_foobar, ob, -1000) == " . str::posIgnoreCase('Ob_foobar', 'ob', -1000), "\n";
echo "--last-pos\n";
echo "lastPos(ob_foobar, ob) == " . str::lastPos('ob_foobar', 'ob'), "\n";
echo "lastPos(ob_foobar, ob, 4) == " . str::lastPos('ob_foobar', 'ob', 7), "\n";
echo "lastPos(ob_foobar, ob, 100) == " . str::lastPos('ob_foobar', 'ob', 100), "\n";
echo "lastPos(ob_foobar, ob, -1) == " . str::lastPos('ob_foobar', 'ob', -1), "\n";
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";
?>
--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
Пример #4
0
--TEST--
php\lib\str Test - misc
--FILE--
<?php 
use php\lib\str;
echo "length(foobar) == " . str::length('foobar'), "\n";
echo "lower(FOObar) == " . str::lower('FOObar'), "\n";
echo "upper(FOObar) == " . str::upper('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";
?>
--EXPECT--
length(foobar) == 6
lower(FOObar) == foobar
upper(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