且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将ereg_replace更改为等效的preg_replace

更新时间:2023-02-18 09:15:34

preg_replace('/^' . preg_quote($g_lang_prefix,'/') . '/', '', $t_var );

如果需要$g_lang_prefix作为通用正则表达式,则省略preg_quote

If you need $g_lang_prefix working as a common regex then omit preg_quote

preg_replace('/^' . $g_lang_prefix . '/', '', $t_var );

(非常明显)

如果您需要第二种解决方案,但您的$g_lang甚至可以包含此字符/,那么您至少需要对其进行转义:

Also if you need this second solution, but your $g_lang can contain even this char / then you need to escape at least it:

preg_replace('/^' . str_replace('/','\/',$g_lang_prefix) . '/', '', $t_var );