0

How do I change eregi_replace in this code to preg_replace()?

This is the original code:

$title = eregi_replace('</?[a-z][a-z0-9]*[^<>]*>', '', $title );

Do I just need to overwrite eregi_replace with preg_replace or do I need to do more?

I tried this and some variations:

$title = preg_match('#<\/?[a-z][a-z0-9]*[^<>]*>#', '', $title );

When title is submited it turns into 0 and the value is lost.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153

1 Answers1

1

Here I shall make an easy answer that other users don't take time to reply:

eregi_replace() uses POSIX regex and preg_replace() uses Perl Compatible Regular Expressions PCRE, they can have differences.

But in your case with a good formed regex, it remains the same. It removes all HTML tags in the title text:

Old regex:

$title = eregi_replace('</?[a-z][a-z0-9]*[^<>]*>', '', $title );

New regex:

$title = preg_replace('#</?[a-z][a-z0-9]*[^<>]*>#i', '', $title );
jacouh
  • 8,473
  • 5
  • 32
  • 43