Results 1 to 5 of 5

Thread: [RESOLVED] PHP Proper Case

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Resolved [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!

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: PHP Proper Case

    Fantastic! Cheers Manavo!!

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  5. #5

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    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
  •  



Click Here to Expand Forum to Full Width