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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:45:54+00:00 2026-05-20T14:45:54+00:00

I want to implement a small routine that generates the plural form of the

  • 0

I want to implement a small routine that generates the plural form of the name of an entity in Spanish. Basically, it takes a WordInCSharpCase or a wordInJavaCase, such as MedioDePago (payment method), and it appends an “s” at right before the first non-lowercase character (excluding the first character), which in this case would produce the string MediosDePago (payment methods). In C#, this routine was:

public string Pluralize(string input)
{
    int i = 0;
    while (++i < input.Length)
        if (!char.IsLower(input[i]))
            break;

    StringBuilder builder = new StringBuilder(input);
    builder.Insert(i, 's');
    return builder.ToString();
}

Now I need to implement this routine in PHP, but I cannot find an equivalent of C#’s char.IsLower. The only thing I have found is ctype_lower, but it takes a string as an input, and creating/testing/discarding several strings would be too inefficient. Does PHP have a function that tests whether a single character is in lower 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-20T14:45:54+00:00Added an answer on May 20, 2026 at 2:45 pm

    Well, first off, creating several strings is not inefficient. A string is a native type in PHP and it’s quite efficient at doing it. What I would do is something like this:

    $callback = function($match) {
        return $match[1] . 's' . $match[2];
    };
    
    $string = preg_replace_callback('/^([A-Za-z][a-z]*)([A-Z]|$)/', $callback, $string);
    

    Or, as @Kevin suggests in the comments:

    $string = preg_replace('/^([A-Za-z][a-z]*)([A-Z]|$)/', '\1s\2', $string);
    

    It’s more efficient since it doesn’t need to capture past the first non-lowercase character.

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

Sidebar

Related Questions

I wrote small service class and I want implement something like that : service
I want to implement a utility for myself that should provide a small console
I want to implement something simple like /System/Workflows/Sample Workflow with the small addition of
Possible Duplicates: How would I implement stackoverflow’s hovering dialogs? i want a small box
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
i want to implement a small search engine , i have index page where
I'm building a small social site, and I want to implement an activity stream
I want to implement this: A ScrollView that contains many elements (ImageViews, TextViews, EditTexts
I've made a small application for fun and I want to implement an update
I'm working on some small chat application. I want to implement smilies over there

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.