i have the following preg_replace script, which is a part of a bbcode replace script;
but what i need to do instead is surround the image tag with a link tag, linking to the same src in the image, and then i need to change the src of the image tag to the link to the thumbnail. for example;
instead of this code:
i want this code:
i guess a preg_replace function is probably not the right one to use, but i dont know how to do this, and a preg_replace function actually changes all the occurences of the expression. How do i do this?
Code:
// Search for this...
$replacewhat = array(
'/\[img][/img](.+?)\[\/img\]/i',
'/\[img]width=([0-9[/img]+) height=([0-9]+)\s*\](.+?)\[\/img\]/i',
'/\[img]width=([0-9[/img]+)\s*\](.+?)\[\/img\]/i',
'/\[img]height=([0-9[/img]+) width=([0-9]+)\s*\](.+?)\[\/img\]/i',
'/\[img]height=([0-9[/img]+)\s*\](.+?)\[\/img\]/i',
);
// ...and replace it with this
$replacewith = array(
'<img src="\\1" alt="" />',
'<img src="\\3" alt="" width="\\1" height="\\2" />',
'<img src="\\2" alt="" width="\\1" />',
'<img src="\\3" alt="" width="\\2" height="\\1" />',
'<img src="\\2" alt="" height="\\1" />',
);
$news = preg_replace($replacewhat, $replacewith, $news);
but what i need to do instead is surround the image tag with a link tag, linking to the same src in the image, and then i need to change the src of the image tag to the link to the thumbnail. for example;
instead of this code:
Code:
<img src="[URL unfurl="true"]http://www.WHATEVER.com/WHATEVER/images/imagefile.jpg"[/URL] width="x" height="y">
i want this code:
Code:
<a href="[URL unfurl="true"]http://www.WHATEVER.com/WHATEVER/images/imagefile.jpg"><img[/URL] src="[URL unfurl="true"]http://www.WHATEVER.com/WHATEVER/images/mini/pre_imagefile.jpg"[/URL] width="80" height="80" border="0">
i guess a preg_replace function is probably not the right one to use, but i dont know how to do this, and a preg_replace function actually changes all the occurences of the expression. How do i do this?