DEV Community

Discussion on: Daily Challenge #47 - Alphabets

Collapse
 
celyes profile image
Ilyes Chouia • Edited

a bit late but here's the answer anyway... in PHP

function alphabet_position($text){
    $alphabet = range('a', 'z');     
    $strippedText = str_split(strtolower(preg_replace("/[^a-zA-Z]/", "", $text)));   
    $result = "";
    foreach($strippedText as $letter){
        $result .= array_search($letter, $alphabet)+1 . " ";   
    }
    return $result;
}
echo alphabet_position("The sunset sets at twelve o' clock.");