fork download
  1. <?php
  2. $sequence = '1000111001110011011001111';
  3. preg_match_all("/1+/", $sequence, $matches);
  4. foreach ($matches[0] as $match) $result[strlen($match)]++;
  5. echo '<pre>'; print_r($result);
Success #stdin #stdout #stderr 0.01s 82944KB
stdin
Standard input is empty
stdout
<pre>Array
(
    [1] => 1
    [3] => 2
    [2] => 2
    [4] => 1
)
stderr
PHP Notice:  Undefined variable: result in /home/NtS1Ql/prog.php on line 4
PHP Notice:  Undefined offset: 1 in /home/NtS1Ql/prog.php on line 4
PHP Notice:  Undefined offset: 3 in /home/NtS1Ql/prog.php on line 4
PHP Notice:  Undefined offset: 2 in /home/NtS1Ql/prog.php on line 4
PHP Notice:  Undefined offset: 4 in /home/NtS1Ql/prog.php on line 4