Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 168611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:29:02+00:00 2026-05-11T12:29:02+00:00

I have a large number of strings to process in php. I want to

  • 0

I have a large number of strings to process in php. I want to ‘fix’ them to be title case (using ucwords(strtolower($str))) but only if they are all upper or all lower case already. If they are already mixed case, I’d just rather just leave them as they are.

What is the fastest way to check for this? It seems like foring through the string would be a rather slow way to go about it.

Here’s what I have, which I think will be too slow:

function fixCase($str) {     $uc = 0;     $lc = 0;     for($i=0;$i<strlen($str);$i++)     {         if ($str[$i] >= 'a' && $str[$i] <= 'z')             $lc++;         else if ($str[$i] >= 'A' && $str[$i] <= 'Z')             $uc++;     }      if ($uc == 0 || $lc == 0)     {         return ucwords(strtolower($str));     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:29:03+00:00Added an answer on May 11, 2026 at 12:29 pm

    just use a string compare (case sensitive)

    function fixCase($str) {   if (         (strcmp($str, strtolower($str)) === 0) ||         (strcmp($str, strtoupper($str)) === 0) )    {     $str = ucwords(strtolower($str));   }    return $str; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I went through some testing with this as well. If… May 11, 2026 at 3:18 pm
  • added an answer Please see: Pseudo-random number generator True random number generator Fast… May 11, 2026 at 3:18 pm
  • added an answer sys.foreign_keys was introduced in SQL Server 2005. You'll have to… May 11, 2026 at 3:18 pm

Related Questions

I have a decent sized set of data that needs to be stored in
Suppose I have a large number of strings formatted something like: <tag>blah blahXXXXXblah blah</tag>
We have a few operations where we are doing a large number of large
I am looking for a method of storing Application Messages, such as You have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.