PHP code example of jasonlam604 / stringizer

1. Go to this page and download the library: Download jasonlam604/stringizer 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/ */

    

jasonlam604 / stringizer example snippets




// Composer Autoloader
$s = new Stringizer("myapp");

$s->ensureRight("/");

// The following outputs: myapp/
echo $s->getString(); 


$s = new Stringizer("44GT44KT44Gr44Gh44Gv");
$s->base64Decode(); // こんにちは

$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->base64Encode(); // yJjFpsWXw43DscSdw6x6xJXFlQ==

$s = new Stringizer("<div>ȘŦŗÍñĝìzĕŕ</div>");
$s->between("<div>", "</div>"); // ȘŦŗÍñĝìzĕŕ

$s = new Stringizer("data_rate");
$s->camelize(); // dataRate

$s = new Stringizer("helloSŦŗÍñĝìzĕŕ");
$s->camelToSnake(); // hello_sŦŗÍñĝìzĕŕ

$s = new Stringizer("Foo Bar Fizz Buzz");
$s->charAt(4); // B

$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->chars(); // an array made up 10 indexes ["Ș","Ŧ","ŗ","Í","ñ","ĝ","ì","z","ĕ","ŕ"]

$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->charAt(1); // Ŧ

$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->charAt(0); // S

$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->chompLeft("ȘŦŗÍñĝ"); // ìzĕŕ

$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->chompRight("ìzĕŕ"); // ȘŦŗÍñĝ

$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->chopLeft("ȘŦŗÍñĝ"); // ìzĕŕ

$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->chopRight("ìzĕŕ"); // ȘŦŗÍñĝ

$s = new Stringizer(""ȘŦŗÍñĝ\n\nìzĕŕ \n\t    \r"");
$s->concat("collapseWhitespace") // ȘŦŗÍñĝ ìzĕŕ

$s = new Stringizer("fizz");
$s->concat(" buzz") // fizz buzz

$s = new Stringizer(" buzz");
$s->concat("fizz",true) // fizz buzz

$s = new Stringizer("fizz buzz foo bar");
$s->contains("buzz"); // true

$s = new Stringizer("fizz buzz foo bar");
$s->contains("Buzz"); // false, case sensitive

$s = new Stringizer("fizz buzz foo bar");
$s->containsIncaseSensitive("Buzz"); // true, case insensitive

$s = new Stringizer("fizz buzz fizz buzz fizz buzz");
$s->containsCount("buzz"); // 3

$s = new Stringizer("fizz buzz fizz buzz fizz buzz");
$s->containsCount("nomatch"); // 0

$s = new Stringizer("fizz buzz foo bar");
$this->assertEquals(0, $s->containsCount("BUZZ")); // 0, case sensitive no match found

$s = new Stringizer("fizz buzz foo bar");
$s->containsCountIncaseSensitive("BUZZ"); // 1, case in-sensitive 1 match found

$s = new Stringizer("文字列のそれ 文字列のそれ 文字列のそれ 文字列のそれ");
$this->assertEquals(4, $s->containsCount("れ")); // 4

$s = new Stringizer("dataRate");
$s->dasherize(); // data-rate

$s = new Stringizer("Fizz 列Fizz列 Fizz");
$s->delete("列"); //Fizz Fizz Fizz
  
$s = new Stringizer("Fizz Buzz");
$s->endsWith("zz"); // true

$s = new Stringizer("文字列のそれ");
$s->endsWith("れ"); // true
     
$s = new Stringizer("文字列のそれ");
$s->endsWith("れれれれ"); // false
  
$s = new Stringizer("/myapp");
$s->ensureLeft("/"); //  /myapp
  
$s = new Stringizer("/myapp");
$s->ensureRight("/"); //  /myapp/
  
$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->first(6); // ȘŦŗÍñĝ
  
$s = new Stringizer("Hello, World");
$s->hashCode(); // -505841268
  
$s = new Stringizer("stŗiñĝìzĕŕ");
$s->hasLowercase()); // true
  
$s = new Stringizer("sTŗiñĝìzĕŕ");
$s->hasLowercase()); // false
  
$s = new Stringizer("STÃÑ");
$s->hasUppercase()); // true
  
$s = new Stringizer("StÃÑ");
$s->hasUppercase()); // false
  
$s = new Stringizer("Fizz Buzz Foo Bar");
$s->indexOf("Foo"); // 10
  
$s = new Stringizer("Fizz Buzz Foo Bar");
$s->indexOf("bad"); // false
  
$s = new Stringizer("Foo Buzz Foo Bar");
$s->indexOf("Foo", 0); // 0, since offset starts at zero the first Foo is found at index 0
$s->indexOf("Foo", 1); // 9, since offset is past zero the next available match is at index 9
  
$s = new Stringizer("fòô bàř");
$s->indexOf("bàř"); // 4

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->indexOfCaseInsensitive("foo"); // 10

$s = new Stringizer("abcdefghi....12334567890....ABC..XY!!!@#$%^&*()_+=-<>?:;/.,~][}{\|'");
$s->isAscii(); // true

$s = new Stringizer("\x19test\x7F");
$s->isAscii(); // true
$s->isAscii(true); // false

$s = new Stringizer("FooBar");
$s->isAlpha(); // true

$s = new Stringizer("Foo Bar");
$s->isAlpha(); // false

$s = new Stringizer("F00Bar");
$s->isAlphaNumeric(); // true

$s = new Stringizer("F00 Bar");
$s->isAlphaNumeric(); // false

$s = new Stringizer("F00 Bar");
$s->isAlphaNumericSpace(); // true

$s = new Stringizer("F00 Bar !");
$s->isAlphaNumericSpace(); // false

$s = new Stringizer("Marie-Anne Lucy");
$s->isAlphaNumericSpaceDash(); // true

$s = new Stringizer("Marie-Ann Lucy!");
$s->isAlphaNumericSpaceDash(); // false

// Decoded value is ȘŦŗÍñĝìzĕŕ
$s = new Stringizer("yJjFpsWXw43DscSdw6x6xJXFlQ==");
$s->isBase64(); // true

$s = new Stringizer("\n  \n\r\t   ");
$s->isBlank(); // true

date_default_timezone_set('America/Vancouver');
$s = new Stringizer("2015-03-15");
$s->isDate(); // true

date_default_timezone_set('America/Vancouver');
$s = new Stringizer("January 1st");
$s->isDate(); // true

$s = new Stringizer("19.99");
$s->isDecimal(); // true

$s = new Stringizer("19");
$s->isDecimal(); // true

$s = new Stringizer("19x");
$s->isDecimal(); // false

$s = new Stringizer("[email protected]");
$s->isEmail(); // true

$s = new Stringizer("John.Doe@[email protected]");
$s->isEmail(); // false

$s = new Stringizer("\n  \n\r\t   ");
$s->isEmpty(); // true

$s = new Stringizer("3ca25ae354e192b26879f651a51d92aa8a34d8d3");
$s->isHash("sha1"); // true

$s->setString("3ca25ae354e192b26879f651a51d92aa8a34d8d3");
$s->isHash("Tiger160"); // true

$s->setString("579282cfb65ca1f109b78536effaf621b853c9f7079664a3fbe2b519f435898c");
$this->assertEquals(true, $s->isHash("sha256"); // true

$s->setString("bf547c3fc5841a377eb1519c2890344dbab15c40ae4150b4b34443d2212e5b04aa9d58865bf03d8ae27840fef430b891");
$this->assertEquals(true, $s->isHash("sha384"); // true

$s->setString("45bc5fa8cb45ee408c04b6269e9f1e1c17090c5ce26ffeeda2af097735b29953ce547e40ff3ad0d120e5361cc5f9cee35ea91ecd4077f3f589b4d439168f91b9");
$this->assertEquals(true, $s->isHash("sha512"); // true

$s->setString("46fc0125a148788a3ac1d649566fc04eb84a746f1a6e4fa7");
$this->assertEquals(true, $s->isHash("tiger192"); // true

$s = new Stringizer("CCDDEE");
$s->isHexColor(); // true

$s = new Stringizer("#CCDDEE");
$s->isHexColor(); // false

$s = new Stringizer("ZZZZZZ");
$s->isHexColor(); // false

$s = new Stringizer("AB10BC99");
$s->isHexDecimal(); // true

$s = new Stringizer("ISBN:0-306-40615-2");
$s->isIsbn10() // true

$s = new Stringizer("ISBN:979-1-090-63607-1");
$s->isIsbn13() // true

$s = new Stringizer("192.168.1.1");
$s->isIpv4() // true

$s = new Stringizer("2001:cdba:0000:0000:0000:0000:3257:9652");
$s->isIpv6() // true

$s = new Stringizer("{\"foo\" : {
 \"bar\" : \"Hello\",
 \"baz\" : [ \"quuz\", \"norf\" ]
}}");
$s->isJson() // true

$s = new Stringizer("1234");
$s->isNumber() // true

$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->isMultiByte() // true

$s = new Stringizer("Stringizer");
$s->isMultiByte() // false

$s = new Stringizer("37.138");
$s->isLatitude() // true

$s = new Stringizer("-91");
$s->isLatitude() // false

$s = new Stringizer("190");
$s->isLongitude() // true

$s = new Stringizer("191");
$s->isLongitude() // false

$s = new Stringizer("rgb(255,255,255)");
$s->isRgbColor() // true

$s = new Stringizer("FooBar");
$s->isSemver(); // false

$s = new Stringizer("1.0.0");
$s->isSemver(); // true

$s->setString("1.0.0-3.14.6");
$s->isSemver(); // true

$s->setString("0.0.1-beta");
$s->isSemver(); // true

$s = new Stringizer("1.0");
$s->isAlpha(); // false

$s = new Stringizer("https://github.com");
$s->isUrl(); // true

$s = new Stringizer("original-string-overwritten");
$s->join(array("Hello","World","Again")); // Hello,World,Again

$s = new Stringizer("");
$s->join(array("こ","ん","に","ち","は"), "|") // こ|ん|に|ち|は

$s = new Stringizer("");
$s->join(array("こ","ん","に","ち","は"), "") // こんにちは
  
$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->last(4); // ìzĕŕ

$s = new Stringizer("Foo Buzz Foo Bar");
$s->lastIndexOf("Foo"); // 9

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->lastIndexOf("bad"); // false

$s = new Stringizer("Foo Buzz Foo Bar");
$s->lastIndexOf("Foo", 0); // 9 
$s->lastIndexOf("Foo", 4)); // 9
$s->lastIndexOf("Foo", 10)); // false

$s = new Stringizer("fòô bàř fòô bàř fòô bàř");
$s->lastIndexOf("fòô"); // 16

$s = new Stringizer("Fizz Buzz Foo Bar");
$s->lastIndexOf("foo"); //false
$s->lastIndexOfCaseInsensitive("foo"); // 10

$s = new Stringizer("FizzBuzz");
$s->length(); // 8
php
$s = new Stringizer("キラキラした");
$s->length(); // 6
php
$s = new Stringizer("ȘŦŗÍñĝìzĕŕ\nȘŦŗÍñĝìzĕŕ\nȘŦŗÍñĝìzĕŕ");
$s->lineCount(); // 2
php
$s = new Stringizer("FiZZ");
$s->lowercase(); // fizz
php
$s = new Stringizer("FiZz");
$s->lowercaseFirst(); // fIZZ
php
$s = new Stringizer("fizz");
$s->padBoth("x", 10); // xxxfizzxxx
php
$s = new Stringizer("fizz");
$s->padBoth("x", 11); // xxxfizzxxxx
php
$s = new Stringizer("10");
$s->padLeft("0", 5); // 00010
php
$s = new Stringizer("Alien");
$this->assertEquals("Alien     ", $s->padRight(" ", 10)); // "Alien     " 
php
$s = new Stringizer("");
$s->randomAlpha(); // aYvPXitjCJ
php
$s = new Stringizer("");
$s->randomAlpha(20); // cmbOUofxAvWeyMGgPHK
php
$s = new Stringizer("");
$s->randomNumeric(); // 8277761361
php
$s = new Stringizer("");
$s->randomAlphanumeric(); // w5quanvlUP
php
$s = new Stringizer("FizzöBuzz");
$s->repeat(2); // FizzöBuzzFizzöBuzz
php
$s = new Stringizer("こ");
$s->repeat(5); // こここここ
php
$s = new Stringizer("FizzöBuzz Fizz Buzz Fizz Buzzé");
$s->replaceAccents(); // FizzoeBuzz Fizz Buzz Fizz Buzze
php        
$s = new Stringizer("ȘŦŗÍñĝìzĕŕ");
$s->replaceAccents(); // STrIngizer
php
$s = new Stringizer("FizzöBuzz Fizz Buzz Fizz Buzzé");
$s->removeNonAscii(); // FizzBuzz Fizz Buzz Fizz Buzz
php
$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->removeWhitespace(); // FizzBuzzFizzBuzzFizzBuzz
php       
$s = new Stringizer(" Ș Ŧ ŗ Í ñ ĝ ì z ĕ ŕ ");
$s->removeWhitespace(); // ȘŦŗÍñĝìzĕŕ
php
$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->replace("Buzz", "Bar"); // Fizz Bar Fizz Bar Fizz Bar
php
$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->replace(array("Fizz","Buzz"), array("Foo","Bar")); // Foo Bar Foo Bar Foo Bar
php
$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->replace("buzz", "bar"); // Fizz Buzz Fizz Buzz Fizz Buzz
php      
$s = new Stringizer("Fizz Buzz Fizz Buzz Fizz Buzz");
$s->replaceIncaseSensitive("buzz", "bar"); // Fizz bar Fizz bar Fizz bar
php
$s = new Stringizer("Fizz列Buzz列Fizz列Buzz列Fizz列Buzz");
$s->replace("列", " "); // Fizz Buzz Fizz Buzz Fizz Buzz
php        
$s = new Stringizer("mood");
$s->reverse(); // doom
php     
$s = new Stringizer("文字列のそれ");
$s->reverse(); // れその列字文
php
$s = new Stringizer("ȘŦŗÍñĝìzĕŕ jumped over the stringy stick. ȘŦŗÍñĝìzĕŕ jumped over the stringy stick again!  Or did it?");
$s->sentenceCount(); // 3
php        
$s = new Stringizer("Fizz Buzz");
$array = $s->split(" "); // array( 0 => "Fizz", 1 => "Buzz")
php 
$s = new Stringizer("文字列のそれ");
$array = $s->split("の"); // array( 0 => "文字列", 1 => "それ)
php        
$s = new Stringizer("Fizz Buzz");
$s->startsWith("Fizz B"); // true
php
$s = new Stringizer("文字列のそれ");
$s->startsWith("文"); // true
php        
$s = new Stringizer("文字列のそれ");
$s->startsWith("文文文文"); // false
php 
$s = new Stringizer("Hello World! It's me #stringizer");
$s->stripPunctuation(); // Hello World Its me stringizer
php   
$s = new Stringizer("*-=!'\",?!Hello* World][");
$s->stripPunctuation(); // Hello World
php 
$s = new Stringizer("<html>Hello</html>");
$s->stripTags(); // Hello
php         
$s = new Stringizer("<html><b>こんにちは世界</b></html>");
$s->stripTags(); // こんにちは世界
php 
$s = new Stringizer("<html>Hello <b>World</b></html>");
$s->stripTags("<b>"); // Hello <b>World</b>
php 
$s = new Stringizer("<html><head><title>title</title></head><body>Hello <b><span class='fake-class'>World</span></b> こんにちは世界</body></html>");
$s->stripTags(); // titleHello World こんにちは世界
php 
$s = new Stringizer("Fizz Buzz Foo Bar");
$s->subString(0, 4); // Fizz
php 
$s = new Stringizer("Fizz Buzz Foo Bar");
$s->subString(5, 4)); // Buzz
php 
$s = new Stringizer("Fizz Buzz Foo Bar");
$s->subString(5, 4)); // Buzz
php
$s = new Stringizer("キラキラした キラキラした");
$s->subString(7); // キラキラした
php
$s = new Stringizer("hELLO wORLD");
$s->swapCase(); // Hello World
php
$s = new Stringizer("\x20\x20\x20   キラキラしたfizzخالد الشمعة   ");
$s->trim(); // キラキラしたfizzخالد الشمعة
php
$s = new Stringizer("\x20\x20\x20   キラキラしたfizzخالد الشمعة   ");
$s->trimLeft()); // キラキラしたfizzخالد الشمعة   
php
$s = new Stringizer("\x20\x20\x20   キラキラしたfizzخالد الشمعة   ");
$s->trimRight(); // \x20\x20\x20   キラキラしたfizzخالد الشمعة
php
$s = new Stringizer("fòô bàř");
$s->truncate(4); // fòô
php
$s = new Stringizer("FizzBuzz");
$s->truncate(4); // Fizz
php
$s = new Stringizer("fòô bàř");
$s->truncateMatch(" bàř"); // fòô
php
$s = new Stringizer("FizzBuzzFooBar");
$s->truncateMatch("Foo"); // FizzBuzz
php
$s = new Stringizer("FizzBuzzFooBar");
$s->truncateMatchCaseInsensitive("foo"); // FizzBuzz
php
$s = new Stringizer("fIzz");
$s->uppercase(); // FIZZ
php
$s = new Stringizer("fizz buzz foo bar");
$s->uppercaseWords(); // Fizz Buzz Foo Bar
php
$s = new Stringizer("キラキラした");
$s->width(); // 12, note multi-byte characters take up more space, typice 2 for each character
php        
$s = new Stringizer("FizzBuzz");
$s->length(); // 8
php
$s = new Stringizer("ȘŦŗÍñĝìzĕŕ こんにちは ȘŦŗÍñĝìzĕŕ こんにちは ȘŦŗÍñĝìzĕŕ");
$s->wordCount(); // 5


#### setEncoding

Set encoding, behind the scences PHP function mb_internal_encoding is applied