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

  • SEARCH
  • Home
  • 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 947939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:09:43+00:00 2026-05-15T23:09:43+00:00

Assuming I have a string HET1200 text string and I need it to change

  • 0

Assuming I have a string “HET1200 text string” and I need it to change to “HET1200 Text String”. Encoding would be UTF-8.

How can I do that? Currently, I use mb_convert_case($string, MB_CASE_TITLE, "UTF-8"); but that changes “HET1200” to “Het1200.

I could specify an exception, but it won’t be an exhaustive. So I rather all uppercase words to remain uppercase.

Thanks 🙂

  • 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. Editorial Team
    Editorial Team
    2026-05-15T23:09:44+00:00Added an answer on May 15, 2026 at 11:09 pm

    OK, let’s try to recreate mb_convert_case as close as possible but only changing the first character of every word.

    The relevant part of mb_convert_case implementation is this:

    int mode = 0; 
    
    for (i = 0; i < unicode_len; i+=4) {
        int res = php_unicode_is_prop(
            BE_ARY_TO_UINT32(&unicode_ptr[i]),
            UC_MN|UC_ME|UC_CF|UC_LM|UC_SK|UC_LU|UC_LL|UC_LT|UC_PO|UC_OS, 0);
        if (mode) {
            if (res) {
                UINT32_TO_BE_ARY(&unicode_ptr[i],
                    php_unicode_tolower(BE_ARY_TO_UINT32(&unicode_ptr[i]),
                        _src_encoding TSRMLS_CC));
            } else {
                mode = 0;
            }   
        } else {
            if (res) {
                mode = 1;
                UINT32_TO_BE_ARY(&unicode_ptr[i],
                    php_unicode_totitle(BE_ARY_TO_UINT32(&unicode_ptr[i]),
                        _src_encoding TSRMLS_CC));
            }
        }
    }
    

    Basically, this does the following:

    • Set mode to 0. mode will determine whether we are in the first character of a word. If it’s 0, we are, otherwise, we’re not.
    • Iterate through the characters of string.
      • Determine what kind of character it is.
        • Set res to 1 if it’s a word character. More specifically, set it to 1 if it has the property “Mark, Non-Spacing”, “Mark, Enclosing”, “Other, Format”, “Letter, Modifier”, “Symbol, Modifier”, “Letter, Uppercase”, “Letter, Lowercase”, “Letter, Titlecase”, “Punctuation, Other” or “Other, Surrogate”. Oddly, “Letter, Other” is not included.
      • If we’re not in the beginning of a word
        • If we’re at a word character, convert it to lowercase – this is what we don’t want.
        • Otherwise, we’re not at a word character, and we set mode to 0 to signal we’re moving to the beginning of a word.
      • If we’re at the beggining of a word and we indeed have a word character
        • Convert this character to title case
        • Signal we’re no longer at the beginning of a word.

    The mbstring extension does not seem to expose the character properties. This leaves us with a problem, because we don’t have a good way to determine if a character has any of the 10 properties for which mb_convert_case tests.

    Fortunately, unicode character properties in regex can save us here.

    A faithful reproduction of mb_convert_case without the problematic conversion to lowercase becomes:

    function mb_convert_case_utf8_variation($s) {
        $arr = preg_split("//u", $s, -1, PREG_SPLIT_NO_EMPTY);
        $result = "";
        $mode = false;
        foreach ($arr as $char) {
            $res = preg_match(
                '/\\p{Mn}|\\p{Me}|\\p{Cf}|\\p{Lm}|\\p{Sk}|\\p{Lu}|\\p{Ll}|'.
                '\\p{Lt}|\\p{Sk}|\\p{Cs}/u', $char) == 1;
            if ($mode) {
                if (!$res)
                    $mode = false;
            }
            elseif ($res) {
                $mode = true;
                $char = mb_convert_case($char, MB_CASE_TITLE, "UTF-8");
            }
            $result .= $char;
        }
    
        return $result;
    }
    

    Test:

    echo mb_convert_case_utf8_variation("HETÁ1200 Ááxt ítring uii");
    

    gives:

    HETÁ1200 Ááxt Ítring Uii
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There were some additional comments that I posted. But I… May 16, 2026 at 12:10 pm
  • Editorial Team
    Editorial Team added an answer This should do it for you: Intent myIntent = new… May 16, 2026 at 12:10 pm
  • Editorial Team
    Editorial Team added an answer Yes, GetInstance<Database> is a call to a generic method, where… May 16, 2026 at 12:10 pm

Trending Tags

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

Top Members

Related Questions

Assuming you have a string containing the name of a method, an object that
Assuming I have this string: abc{def{ghi{jkl}mno{pqr}st}uvw}xyz and I want to match this: {def{ghi{jkl}mno{pqr}st}uvw} what
Potentially dumb: Assuming I have a string containing an operator what's the best way
Assuming I have the following strings: string str1 = Hello World!; string str2 =
Assuming you have a class Photo: class Photo { public string Title {get; set;}
Assuming I have an object Person with long id String firstName String lastName String
Assuming I have only the class name of a generic as a string in
I have built a WCF Service that is being consumed by a Silverlight app.
Assuming I have a hash like this: $hash_ref = { 'hashes' => { 'h1'
I have the following code: @profile.update_attributes(params[:xxxx_profile]) where xxxx stands for either male or female.

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.