Strip out a bracketed piece of text using PHP

In WordPress I have a free, third-party theme that is displaying my image captions in article excerpts for some reason. The captions show up as a sort of bracketed markup. I tracked down the part of code that prepares the article excerpts and ran this regular expression to strip out any square-bracketed text:


The 'Us' at the end makes the search Ungreedy (U) and ignores newlines (s).

By the way, I think preg_replace() is one of the worst function names I've come across in a public language/API; but maybe that's just me.

Leave a Reply

Your email address will not be published.