I have text (html code) with several images in standard HTML format:
<img src="X" atributos />
I need the src attribute value to be replaced with the CID: # identifier where # is a unique value that identifies each image (see in the code below). That is, each image will have a different value within that attribute.
Below the code I've done so far, it already matches the images correctly. But how to do this replacement?
Another important information is that I need to have in the code the information of which unique identifier has replaced which value (image url) of the src attribute. For example, I need to have a way of knowing that identifier 354 replaced the value "img / xxx.jpg".
preg_match_all('/<img src=[",\']([^>,^\',^"]*)[",\']([^>]*)/', $html, $matches);
$url_imagem = array();
$atributos_imagem = array();
$cid = array();
$contador = 0;
foreach ($matches[1] as $i => $img){
$url_imagem[$contador] = $matches[2][$i];
$atributos_imagem[$contador] = $matches[3][$i];
//Como substituir o conteudo do atributo SRC com o valor da variável $cid abaixo?
$cid[$contador] = "CID:".date('YmdHms').'.'.time();
$contador++;
}