image_n8938.jpg<br>
image_n3472.jpg<br>
image_n8342.jpg<br>
....
может быть несколько картинок
<div class="image"><a href="/original/image_n8938.jpg"><img src="/preview/image_n8938.jpg"></a></div><div class="image"><a href="/original/image_n3472.jpg"><img src="/preview/image_n3472.jpg"></a></div><div class="image"><a href="/original/image_n8342.jpg"><img src="/preview/image_n8342.jpg"></a></div>
<?php
$code =
"image_n8938.jpg<br>
image_n3472.jpg<br>
image_n8342.jpg<br>";
$code = preg_replace("<<br>>","",$code);
$code = preg_replace('/^(.*)$/m', '<div class="image"><a href="/original/$1"><img src="/preview/$1"></a></div>', $code);
echo"$code";
?>
$str = ['image_n8938.jpg', 'image_n3472.jpg', 'image_n8342.jpg', ];
$str2 = [];
foreach ($str as $item) {
array_push($str2,"
<div class=\"image\">
<a href=\"/original/$item\"><img src=\"/preview/$item\"></a>
</div>
<div class=\"image\"><a href=\"/original/$item\">
<img src=\"/preview/$item\"></a>
</div>
<div class=\"image\">
<a href=\"/original/$item\"><img src=\"/preview/$item\"></a>
</div>" );
}