猿问

如何修复preg_match()未知修饰符'?在localeconv()中

问题出在 'decimal_point' => string '/'


但是没有人有好的解决方案吗?


错误:


  preg_match() unknown modifier '?'

功能 :


     * @param   string  $str    input string

     * @return  boolean

     */

    public static function numeric($str)

    {

        // Get the decimal point for the current locale

        list($decimal) = array_values(localeconv());


        // A lookahead is used to make sure the string contains at least one digit (before or after the decimal point)


         return (bool) preg_match('/^-?+(?=.*[0-9])[09]*+'.preg_quote($decimal).'?+[0-9]*+$/D', (string) $str); 

}

这是localeconv()dump:


array (size=18)

  'decimal_point' => string '/' (length=1)

  'thousands_sep' => string ',' (length=1)

  'int_curr_symbol' => string 'IRR' (length=3)

  'currency_symbol' => string 'ريال' (length=8)

  'mon_decimal_point' => string '/' (length=1)

  'mon_thousands_sep' => string ',' (length=1)

  'positive_sign' => string '' (length=0)

  'negative_sign' => string '-' (length=1)

  'int_frac_digits' => int 2

  'frac_digits' => int 2

  'p_cs_precedes' => int 0

  'p_sep_by_space' => int 0

  'n_cs_precedes' => int 0

  'n_sep_by_space' => int 0

  'p_sign_posn' => int 3

  'n_sign_posn' => int 3

  'grouping' => 

    array (size=1)

      0 => int 3

  'mon_grouping' => 

    array (size=1)

      0 => int 3


米琪卡哇伊
浏览 159回答 1
1回答
随时随地看视频慕课网APP
我要回答