I have the following string:
$string = '<img id="Afbeelding_x0020_1" src="cid:image001.png@01D0D37B.5E4E6AE0" alt="logo" height="39" border="0" width="125">';
And I want to replace everything between src="cid:
and "
to a normal img url, so it becomes like this:
$string = '<img id="Afbeelding_x0020_1" src="image.png" alt="logo" height="39" border="0" width="125">';
Everything before and after has to be preserved because it's a whole message, so it's also important to replace only between src="cid:REPLACE@ID"
I have tried this but this does nothing:
$query = "SELECT * FROM tickets WHERE id='".$ticketID."'";
$con = $GLOBALS['db_con']->query($query);
$rd = $con->fetch_assoc();
if(strpos($rd['message'],'src="cid:') !== false){ $bodyImage = extract_unit($rd['message'], 'src="cid:', '@'); }
$imgUrl = 'src="' . $GLOBALS['site_info']['url'] . '/tickets/' . $ticketID . '/' . $bodyImage . '"';
$start = '\src="cid:';
$end = '\"';
$result = preg_replace('#('.$start.')(.*)('.$end.')#si', $imgUrl, $rd['message']);
return $result;
I have this code from: Replacing text between two limts
The $imgUrl
is being build up correcly but preg_replace()
isn't doing anything.
Anyone who knows a solution? Thanks in advance!!!
Solved it by using this code:
function replace_ticketImage($msg,$ticketID,$replyID){
if(strpos($msg,'src="cid:') !== false){
$bodyString = extract_unit($msg, 'src="cid:', '"');
$bodyImage = extract_unit($msg, 'src="cid:', '@');
if($replyID < 1){
$imgUrl = $GLOBALS['site_info']['url'] . '/attachments/tickets/' . $ticketID . '/' . $bodyImage;
} else {
$imgUrl = $GLOBALS['site_info']['url'] . '/attachments/tickets/' . $ticketID . '/' . $replyID . '/' . $bodyImage;
}
$result = preg_replace('/cid:'.$bodyString.'/', $imgUrl, $msg);
} else {
$result = $msg;
}
return $result;
}