<?php
$string = 'WWWDDWWWLLWLLLL';
// The regex matches any character -> . in a capture group ()
// plus as much identical characters as possible following it -> \1+
$pattern = '/(.)\1+/';
preg_match_all($pattern, $string, $m);
// sort by their length
// sort by their length
usort($m[0], 'length_sort');
function length_sort($a, $b) {
return (strlen($a) < strlen($b)) ? 1 : -1;
}
echo "Longest sequence: " . $m[0][0] . "\n";