hip1/9.3.php

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <?php echo capitalise("piet Van der STOEL"); function capitalise($naam){ //list of matches to search for $voorvoegsels = "/aan |af |bij |de |den |der |d'|het |'t|in |onder |op |over |'s|'t|te |ten |ter |tot |uit |uijt |van |ver |voor /i"; //changes the string so that only the first letter of every word is capitalised $naam = ucwords(strtolower($naam)); //returns an array ($matches) which has one nested array //the nested array has a nested array per match from $voorvoegsels found where the first value is the word and the second is the location in the string preg_match_all($voorvoegsels, $naam, $matches, PREG_OFFSET_CAPTURE); //finds and replaces every match with an uncapitalised version for($i=0;$i<count($matches[0]); $i++){ $naam = substr_replace($naam, strtolower($matches[0][$i][0]), $matches[0][$i][1], strlen($matches[0][$i][0])); } return $naam; } ?> </body> </html>

Resultaat

Made by Thijs Aarnoudse