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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.