Alex
Alex

Reputation: 9265

capitalize first and last name with php

I have a string $name that contains a first and last name e.g. Bob Smith, assuming the user types in bob smith I want to be able to capitalize the first letters of their first and last names.

I have tried this: $bar = ucfirst(strtolower($bar)); // Hello world! which only outputs Bob smith. How would one make it so that both the first and last name are capitalized?

Upvotes: 1

Views: 1524

Answers (2)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324650

ucwords

Related Functions are useful.

docs http://img196.imageshack.us/img196/2283/h21r.png

Upvotes: 6

John Conde
John Conde

Reputation: 219834

Use ucwords():

$bar = ucwords(strtolower($bar)); 

Upvotes: 3

Related Questions