Jump to content

Escaping caps


russthebarber

Recommended Posts

Hi,

 

I have set up a simple function so that when a user enters a title in a php form, php gives the first letter of each word a capital letter. As follows:

 

function caps($text){
$search_text=$text;
$search_text=ucwords(strtolower($search_text));
$look_for = "(a";
$change_to = "(A";
$changed_text = str_replace($look_for, $change_to, $search_text);
$search_text=$changed_text;
$look_for = "(b";
$change_to = "(B";
$changed_text = str_replace($look_for, $change_to, $search_text);
$search_text=$changed_text;
$look_for = "(c";
$change_to = "(C";

//...etc...etc.. up to

$look_for = "(z";
$change_to = "(Z";
$changed_text = str_replace($look_for, $change_to, $search_text);
$search_text=$changed_text;
return $search_text;

}

 

The trouble is, if I were to enter the following "The secret of DNA", my function would return "The Secret Of Dna" (removes the caps). Any ideas how to get around this would be most useful. Thanks in advance.

 

Russ

 

 

Link to comment
https://forums.phpfreaks.com/topic/218288-escaping-caps/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.