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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:49:22+00:00 2026-05-26T21:49:22+00:00

I have used a function for formatting in sentence case. My PHP script function

  • 0

I have used a function for formatting in sentence case. My PHP script function is

function sentence_case( $string ) {
    $sentences  = preg_split(
        '/([.?!]+)/', 
        $string, 
        -1, 
        PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
    );

    $new_string = '';
    foreach ( $sentences as $key => $sentence ) {
        $new_string .= ( $key & 1 ) == 0 
            ? ucfirst( strtolower( trim( $sentence ) ) ) 
            : $sentence . ' ';
    }
    $new_string = preg_replace( "/\bi\b/", "I", $new_string );
    //$new_string = preg_replace("/\bi\'\b/", "I'", $new_string);
    $new_string = clean_spaces( $new_string );
    $new_string = m_r_e_s( $new_string );
    return trim( $new_string );
}

Though its going well and converting whole string in sentence case. But I wish it would skip characters in single quote. Like my string HeLLO world! HOw aRE You. is converting to Hello world! How are you?, but I want to skip the content in the single quotes. Like I wish to skip words in the single quotes. 'HELLO' World and convert words in single quotes to uppercase, otherwise string should remain in sentence case.

  • 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-26T21:49:23+00:00Added an answer on May 26, 2026 at 9:49 pm

    You can add another simple regex callback to uppercase words in single quotes. (This is what I understood you want to do.)

    $new_string = preg_replace("/'(\w+)'/e", 'strtoupper("\'$1\'")', $new_string);
    

    If you want this to work for more than one word per quote, use [\w\s]+ in place of \w+. However that would make it more likely to fail for phrases like isn't within the text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used the explode function in PHP to break up a string into
I have used the crypt function in c to encrypt the given string. I
I have used this function to speak sentence ascynchronously . m_cpVoice->Speak(m_sInputText,SPF_ASYNC, NULL)) I want
I have used sendinput() function and windows keyboard hooks to develop a custom keyboard
Update 2 : So I never have used the debug function in firebug, but
I have used Javascript onlaod like this: function check() { var pic = new
I have a function that I have used a bunch of times in various
I would like to have the choice in a variable_load function (as used to
I have 2 radio buttons and I used mootool while loading as window.addEvent('domready', function()
To get the removable drives i have used GetDriveType ( ) function Is it

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.