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
  • 344,413
  • 96
  • 627
  • 693

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
  • 68,891
  • 9
  • 93
  • 99
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,029
  • 4
  • 22
  • 43