PHP code example of bag2php / iter-string

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

    

bag2php / iter-string example snippets




use function Bag2\iter\string\each_byte;

$string = "abcdef";

foreach (each_byte($string) as $s) {
    echo $s, PHP_EOL;
}
// a
// b
// c
// d
// e



use function Bag2\iter\string\each_codepoint;

$string = "一二三123あいうABC가나다";

foreach (each_codepoint($string) as $s) {
    echo $s, PHP_EOL;
}
// 一
// 二
// 三
// 1
// 2
// 3
// あ
// い
// う
// A
// B
// C
// 가
// 나
// 다



use function Bag2\iter\string\each_grapheme;

$string = "一二三123あいうABC가나다";

foreach (each_grapheme($string) as $s) {
    echo $s, PHP_EOL;
}