I am trying to get this if statement to follow as: if the first string position is .png, then get $png1 from a haystack, but if the first string position is .jpg, then get $jpg1 from the haystack, but if it is .gif, get $gif1 from haystack, else if none of them are found then the string position is .bmp so get $bmp1
Here is what i tried, but it doesn't parse correctly:
/***************************** 1st image in email**********************************/
// if first occurence is .png get $png1 needle from haystack
if (preg_match('/cid:([^"@]*).png@([^"]*)/', $html_part))
{ $find = '/cid:([^"@]*).png@([^"]*)/';
$replace1 = $png1;
$html_part = preg_replace($find, $replace, $html_part);
}
// if first occurence is .jpg get $jpg1 needle from haystack
elseif (preg_match('/cid:([^"@]*).jpg@([^"]*)/', $html_part))
{ $find = '/cid:([^"@]*).jpg@([^"]*)/';
$replace1 = $jpg1;
$html_part = preg_replace($find, $replace, $html_part);
}
// if first occurence is .gif then get $gif1 needle from haystack
elseif (preg_match('/cid:([^"@]*).gif@([^"]*)/', $html_part))
{ $find = '/cid:([^"@]*).gif@([^"]*)/';
$replace = $gif1;
$html_part = preg_replace($find, $replace, $html_part);
}
// if first occurence is .bmp then get $bmp1 needle from haystack
else
{ $find = '/cid:([^"@]*).bmp@([^"]*)/';
$replace = $bmp1;
$html_part = preg_replace($find, $replace, $html_part);
}
and repeated forth for a total for 5 images The problem is the if statements don't return as i would've hoped. They just replace the reference with the last thing matched in the entire sequence (On a scale of repeating this 5 times)
An example $html_part, with line breaks added for display, is:
<b>Bold Text.</b> <i>Italicized Text.</i> <u>Underlined Text.</u> Plain Unformatted Text.
<img width=183 height=183 id="Picture_x0020_3" src="cid:image001.png@01CCCB31.E6A152F0"
alt="Description: Description: Description: cid:image001.png@01CCC701.5A896430">
<img width=153 height=145 id="Picture_x0020_2" src="cid:image002.jpg@01CCCB31.E6A152F0"
alt="Description: Description: cid:image002.jpg@01CCCB1D.D3A29740"><img width=182 height=123
id="Picture_x0020_1" src="cid:image003.jpg@01CCCB31.E6A152F0"
alt="Description: Description: cid:image003.jpg@01CCCB1D.D3A29740">
Could someone help me find a solution for this? Thanks