Jump to content

[SOLVED] preg_replace only replaces the last match


cleggy

Recommended Posts

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.