Interesting task :-) Here is my solution:
<?php
$usernames = explode(", ", readline());
foreach ($usernames as $username) {
$length = strlen($username);
if ($length >= 3 && $length <= 16) {
$isValid = true;
for ($i = 0; $i < $length; $i++) {
$currChar = $username[$i];
if (!(ctype_alnum($currChar) || $currChar === "_" || $currChar === "-")) {
$isValid = false;
break;
}
}
if ($isValid) {
echo $username . PHP_EOL;
}
}
}