Here ya go, hope this helps ya 😉
<?php
$output_document = "
\n<br> asdf asdf 😃<br><br>\n\n
";
while(preg_match("/[img=\"([-.\/a-zA-Z0-9!&%#?,'=:~])\"( align=\"([a-zA-Z0-9])\")?( alt=\"([-.\/a-zA-Z0-9!&%#?,'=:~$ ()])\")?( border=\"([0-9])\")?( link=\"([-.\/a-zA-Z0-9!&%#?,'=:~]*)\")?]/i",$output_document,$image_data)) {
unset($image); // Clear this so that the image is not appended to previously replaced images
$image_url = $image_data[1];
$image_align = $image_data[3];
$image_alt = $image_data[5];
$image_border = $image_data[7];
$image_link = $image_data[9];
$image_alt = eregi_replace("\'\'","\"",$image_alt);
if (!eregi("^.*/",$image_url) || !eregi("^http[s]*://",$image_url)) {
$image_url = $siteroot."images/docs/$doc_id/$image_url";
}
if (eregi("center",$image_align)) {
$image .= "<center>";
}
if (isset($image_data[8])) {
if (!eregi("^.*/",$image_link) || !eregi("^http[s]*://",$image_link)) {
$image_link = $siteroot."images/docs/$doc_id/$image_link";
}
$image .= "<a href=\"$image_link\">";
}
$image .= "<img src=\"$image_url\"";
if (isset($image_data[2])) {
$image .= " align=\"$image_align\"";
if (eregi("left",$image_align) || eregi("right",$image_align)) {
$image .= " vspace=\"$image_vspace\" hspace=\"$image_hspace\"";
}
}
if (isset($image_data[4])) {
$image .= " alt=\"$image_alt\"";
}
if (isset($image_data[6])) {
$image .= " border=\"$image_border\"";
} else {
$image .= " border=\"0\"";
}
$image .= ">";
if (isset($image_data[8])) {
$image .= "</a>";
}
if (eregi("center",$image_align)) {
$image .= "</center>";
}
$output_document = str_replace($image_data[0],$image,$output_document);
}
echo $output_document;
?>
===========================================
That should do it for ya... I even changed it from eregi to preg_match (it is still case insensitive). Now, here are the things I had to modify in order to get this to run besides placing it in the while loop..
First of all, I had to make sure that instead of using eregi_replace() at the bottom (which would replace ALL occurances with $image) to str_replace() so it would only replace the exact one (or if there are duplicates, but this is OK if they are the exact same).
The other change I had to make was to unset($image) at the top of the while loop so it didn't keep appending data to $image and replacing (you can try it for yourself without unset($image) and you'll know what I mean).
Well anyways, let me know if that helps ya 🙂