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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:17:25+00:00 2026-05-30T22:17:25+00:00

The expression is for calculating the form of a plural string for Gettext. Example:

  • 0

The expression is for calculating the form of a plural string for Gettext. Example:

$expr = 'n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2';

with eval I’m doing something like:

$expr = str_replace('n','$n', $expr);

$n = 5;
$result = (int)eval("return $expr;");

Can this be done without eval too?

  • 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-30T22:17:26+00:00Added an answer on May 30, 2026 at 10:17 pm

    Even though it is possible to build a parser that would be able to parse limited amount (you need only trivial math operators to calculate plurals) it doesn’t worth it in terms of time you spend implementing it and performance (obviously it will be slower).

    So I’d personally go with eval() or just implement a function per language you need to pluralize.

    It is one of the cases when I assume eval as not “evil” as long as its input is predefined by you

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

Sidebar

Related Questions

i've a prob here, so i need a help:) When i'm calculating expression like
I got a linq expression, internal T Execute<T>(System.Linq.Expressions.Expression<Func<int, string, T>> expr) { var paramInt
i want to print the expression Xmin and Ymin as is without calculating the
Is there a Regular Expression that can detect SQL in a string? Does anyone
I have a complex expression calculating a value from a date that I have
I have a large mathematical expression that has to be created dynamically. For example,
Is it possible to draw a frame around an expression? For example if I
I am using a regular expression like <cfset a = ReFind(DESCRIBE\+[^>]*>, myResult.Header, 1, true)
I would like to optimize a part of my program where I'm calculating the
I'm using a linq query which looks (after some simplification) something like the following:

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.