cleggy Posted August 8, 2007 Share Posted August 8, 2007 Hi - I'm trying to add a class to any PDF links. The following almost works, but only replaces the last match! $pattern = '/(<a.+href.*=.*".+\.pdf")(.*>)(.*<\/a>)/'; $replacement = '$1 class="pdfLink"$2$3'; $string = preg_replace($pattern, $replacement, $string); Can you please tell me how to make it replace all matches? Thanks! Quote Link to comment Share on other sites More sharing options...
effigy Posted August 8, 2007 Share Posted August 8, 2007 Your modifiers are greedy. Make them ungreedy by following them with a question mark, or use the /U modifier. Quote Link to comment Share on other sites More sharing options...
cleggy Posted August 8, 2007 Author Share Posted August 8, 2007 Thank you! And thanks so much for the quick response! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.