开发者

Changing ereg_replace to equivalent preg_replace [duplicate]

开发者 https://www.devze.com 2023-03-11 06:32 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicates: How can I convert ereg expressions to preg in PHP?
This question already has answers here: Closed 11 years ago.

Possible Duplicates:

How can I convert ereg expressions to preg in PHP?

What is the equivalent using preg_replace to the following expression?

ereg_replace('^' . $g_lang_pre开发者_如何学运维fix, '', $t_var );


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

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

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

(quite obvious)

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 );
0

精彩评论

暂无评论...
验证码 换一张
取 消