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 3210804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:37:22+00:00 2026-05-17T14:37:22+00:00

Take two strings: o’sulLivAn doUble-baRrel Desired result: O’Sullivan Double-Barrel I thought ucwords(strtolower($str)) might do

  • 0

Take two strings:

"o'sulLivAn"
"doUble-baRrel"

Desired result:

"O'Sullivan"
"Double-Barrel"

I thought ucwords(strtolower($str)) might do the trick but it treats the strings as a single word.

I know I can explode, or rather preg_split the string and then capitalize the parts and put it back together again, but I’m wondering if there’s a better way of doing it?

Usually with PHP and this sort of thing there tends to be a function hiding away somewhere that’d be useful but isn’t obvious or well known.

  • 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-17T14:37:23+00:00Added an answer on May 17, 2026 at 2:37 pm

    There’s no php function to do this.

    Here’s a one-liner with no loop (kinda)

    $str1 = "double-barrel";
    $str2 = "o'sulLivAn";
    
    
    function my_ucase( $str, $chars="-'" ) {
        return implode(array_map( 'ucwords', array_map( 'strtolower', preg_split( "~([".$chars."])~", $str, null, PREG_SPLIT_DELIM_CAPTURE ))));
    }
    
    echo my_ucase($str1);
    echo my_ucase($str2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to take two strings and combine them into a single path string
My aim is to take two strings and compare there ends if both of
I'm trying to take two strings and print them out in alphabetical order. For
For an assesment in C i have to take two files with strings within
Help please to compare two strings and take the difference between them in percent
I am trying to take two strings (message1, message2), assign str1 to message1 if
Please take a look at two connection strings, One to Access database and the
I want to take two lists and find the values that appear in both.
Here's my (code golf) challenge: Take two arrays of bytes and determine if the
Is there any way I can take two WinForms elements of the same size/type,

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.