function makeTitle($string) { $ignore = array('a','an','and','as','at','but','by','for','in','nor','of','on','or','per','the','to'); $words = explode(' ', $string); foreach ($words as $key => $word) { if (!in_array($word, $ignore)) { $words[$key] = ucfirst($word); } } return implode(' ', $words); } echo makeTitle("the lord of the rings"); // Output: "The Lord of the Rings"
function makeTitle($string) { $ignore = array('a','an','and','as','at','but','by','for','in','nor','of','on','or','per','the','to'); $words = explode(' ', $string); foreach ($words as $key => $word) { if (!in_array($word, $ignore)) { $words[$key] = ucfirst($word); } } return implode(' ', $words); } echo makeTitle("a brief history of time"); // Output: "A Brief History of Time"Package/library: This function does not require any external package or library, it is a simple PHP function that can be used in any PHP project.