You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP技术问题:如何排除单词“mois”以避免为其添加后缀's'

How to Prevent Adding 's' Suffix to the Word "mois" in PHP

Got it, let's tackle this problem where you don't want the word "mois" to get an automatic 's' suffix in your PHP code. Here are a few straightforward approaches depending on how your pluralization is set up:

1. Add an Exclusion Check in Your Custom Pluralization Function

If you're using a custom function to handle pluralizing words, the simplest fix is to add a condition that skips the suffix for "mois":

function get_plural($word) {
    // Bypass pluralization for "mois"
    if ($word === 'mois') {
        return $word;
    }
    // Your existing pluralization logic here (e.g., adding 's' by default)
    return $word . 's';
}

Now when you call get_plural('mois'), it'll return mois instead of moiss, while other words will still get their suffix as usual.

2. Special Handling for Framework/Built-in Plural Tools

If you're relying on a framework's built-in pluralization function (like WordPress's _n() or Symfony's Intl component), you can either:

  • Hardcode the plural form for "mois" directly in the function call:
    // For WordPress: use the same word for both singular and plural
    echo _n('mois', 'mois', $item_count);
    
  • Or add a conditional check before calling the framework function:
    $target_word = 'mois';
    $plural_form = ($target_word === 'mois') ? $target_word : _n($target_word, $target_word . 's', $item_count);
    echo $plural_form;
    

3. Regex-Based Fix for Batch Text Processing

If you're dealing with processed text where "moiss" might have already been added, you can clean it up with a simple replacement:

// Correct any accidental "moiss" instances back to "mois"
$processed_text = str_replace('moiss', 'mois', $processed_text);

Or if you want to prevent it upfront, create a list of excluded words and check against it:

function safe_pluralize($word) {
    $excluded_words = ['mois']; // Add other words to exclude here if needed
    if (in_array(strtolower($word), $excluded_words)) {
        return $word;
    }
    // Default pluralization logic
    return $word . 's';
}

内容的提问来源于stack exchange,提问作者thmsgrmd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:13:46