[wp-hackers] wp_trim_excerpt

Austin Matzko if.website at gmail.com
Wed Mar 11 02:53:52 GMT 2009


On Tue, Mar 10, 2009 at 9:20 PM, Jason Webster <jason at intraffic.net> wrote:
> You should watch your regex for removing the script tags there...
> "<" is still a valid character in javascript. So, your regex won't strip out
> script tags that are escaped with CDATA tags, or use the less than operator,
> or contain a string with the less than character.
>
> A better bet may be to use (.+?), which will take out everything until it
> hits the (first) closing script tag.

Also, you may want to add the case-insensitive and dot-matches-all
modifiers (to catch script tags that go over more than one line), and
as Jason suggests, a lazy quantifier.  And you may as well get the
style elements in one swipe.

$text = preg_replace('#<(s(cript|tyle)).*?</\1>#si', '', $text);


More information about the wp-hackers mailing list