Warning: preg_replace(): Unknown modifier 'g'

前端 未结 3 960
粉色の甜心
粉色の甜心 2020-11-30 07:16

I got an error by this regular expression...

$strTmp = preg_replace(\'~(<\\/CharacterStyleRange>(.*?)\\n*)~gim \' , \"

        
相关标签:
3条回答
  • 2020-11-30 07:49

    You don't have to specify the global flag. From the documentation, there is a separate parameter ($limit) used to specify the number of replacements to make:

    limit The maximum possible replacements for each pattern in each subject string. Defaults to -1 (no limit).

    So, unless you specify a positive number for this parameter, it will replace all occurrences by default:

    $strTmp = preg_replace('~(<\/CharacterStyleRange>(.*?)\n*</CharacterStyleRange>)~im ' , "</CharacterStyleRange>", $strTmp);
    
    0 讨论(0)
  • 2020-11-30 07:54

    There is a / before the letter G in the string you're replacing.

    0 讨论(0)
  • 2020-11-30 07:57

    g is implicit with preg_replace(). You don't need to include it.

    0 讨论(0)
提交回复
热议问题