|
-
Oct 3rd, 2008, 12:18 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] PHP Proper Case
I know that PHP has not function to set a string to proper case, look at the example below.
Original string - "an article from a book"
PHP ucwords() - "An Article From A Book"
Expected Result -"An Article from a Book"
Now, the following words that are not at the start of a string should not be capatilised...
Code:
if, as, and, then, the, than etc
So... is their a function that will properly capatilise a string, if not, where can I get a list of words, such as those in the example above.
Thanks!
-
Oct 3rd, 2008, 12:36 PM
#2
-
Oct 3rd, 2008, 02:07 PM
#3
Thread Starter
Frenzied Member
Re: PHP Proper Case
Fantastic! Cheers Manavo!!
-
Oct 4th, 2008, 12:13 AM
#4
Re: PHP Proper Case
Unfortunately function in that link contains many errors — read the comments to see a few. Also it is grossly inefficient.
There really isn't an easy way to do this. I would start by consulting a manual of style which is appropriate to your locale and context, and only then implementing the rules in code.
-
Oct 4th, 2008, 07:15 AM
#5
Thread Starter
Frenzied Member
Re: PHP Proper Case
Thanks pena,
I appreciate that the code may be inefficient, in fact the strings of which I am applying this to are only 4/5 words long, only occur once per script, and is going to be on a script of which isn't going to be used that often.
As a solution without investing too much time, it is in fact perfect.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|