3v4l.org

run code in 300+ PHP versions simultaneously
<?php class test { public static function repeatedCharCount($string) { $lcString = strtolower($string); $prevChar = $lcString[0]; $currentLen = 0; $maxLen = 0; for ($i = 1; $i < strlen($lcString); $i++) { if ($lcString[$i] === $prevChar) { $currentLen += 1; } else { $currentLen = 1; } $maxLen = max($maxLen, $currentLen); $prevChar = $lcString[$i]; } return $maxLen; } public static function consecutiveCharCount($string) { $lcString = strtolower($string); $prevChar = $lcString[0]; $currentLen = 0; $maxLen = 0; $ascending = null; for ($i = 1; $i < strlen($lcString); $i++) { $diff = ord($lcString[$i]) - ord($prevChar); if ($diff == 1) { if ($ascending !== true) { $ascending = true; $currentLen = 1; } $currentLen += 1; } elseif ($diff == -1) { if ($ascending !== false) { $ascending = false; $currentLen = 1; } $currentLen += 1; } else { $currentLen = 1; } $maxLen = max($maxLen, $currentLen); $prevChar = $lcString[$i]; } return $maxLen; } } echo test::consecutiveCharCount("abcdegionoas"); echo test::consecutiveCharCount("EDCb00808asabc"); echo test::consecutiveCharCount("asg7898"); echo test::consecutiveCharCount("asgab876567asfon"); echo test::repeatedCharCount("abcdegionoas"); echo test::repeatedCharCount("EDCb00808asabc"); echo test::repeatedCharCount("asg7898"); echo test::repeatedCharCount("asgaaaCCc656bBBb7asfon");
Output for git.master, git.master_jit, rfc.property-hooks
54341214

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.18 ms | 401 KiB | 8 Q