Articles

Wrap an image tag with a link in PHP

I found the following bit of code useful for automatically creating Joomla lightbox images from image tags.

echo preg_replace('`.+?)src="/([^"]+)"(?.+?)>`','<a class="modal" href="/$2">', $text); 

In this example I've used the Joomla modal behavior but you can easily alter this for Jquery using rel or something similar.