0

i updated my php to 5.3 and i have a problem with my ereg_replace

$txt = ereg_replace("<(/)?(font|span|div|del|ins)[^>]*>","",$txt); 
$txt = ereg_replace("<([^>]*)(class|lang|style|size|face)=(\"[^\"]*\"|'[^']*'|[^>]+)([^>]*)>","<\\1>",$txt);
$txt = ereg_replace("<([^>]*)(class|lang|style|size|face)=(\"[^\"]*\"|'[^']*'|[^>]+)([^>]*)>","<\\1>",$txt);

if i change the ereg_replace to preg_replace i get the warning :

Message: preg_replace() [function.preg-replace]: Unknown modifier ']'

could someone help me fix the preg_replace

Matt Ball
  • 354,903
  • 100
  • 647
  • 710

2 Answers2

1

It is because you don't have pattern delimiters at all. You need to add them.

Try this

$pattern1 = '#<(/)?(font|span|div|del|ins)[^>]*>#';
$pattern2 = '#<([^>]*)(class|lang|style|size|face)=(\"[^\"]*\"|'[^']*'|[^>]+)([^>]*)>#';
$txt = preg_replace($pattern1, '', $txt);
$txt = preg_replace($pattern2, '<\\1>', $txt);

Better yet though, would be to not use regex at all to try to parse HTML like this.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
1
$txt = preg_replace("~<(/)?(font|span|div|del|ins)[^>]*>~","",$txt); 
$txt = preg_replace("~<([^>]*)(class|lang|style|size|face)=(\"[^\"]*\"|'[^']*'|[^>]+)([^>]*)>~","<\\1>",$txt);
$txt = preg_replace(~"<([^>]*)(class|lang|style|size|face)=(\"[^\"]*\"|'[^']*'|[^>]+)([^>]*)>~","<\\1>",$txt);

I've been added delimiters(~) to this expressions. Try.

Roman Nazarkin
  • 2,209
  • 5
  • 23
  • 44