0

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_prefix, '', $t_var );
Toto
  • 89,455
  • 62
  • 89
  • 125
RedDragon
  • 2,080
  • 2
  • 26
  • 42

1 Answers1

5
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 );
dynamic
  • 46,985
  • 55
  • 154
  • 231