4
I have a text (html code) with several images in standard HTML format:
<img src="X" atributos />
I need the value of the attribute src is replaced by the identifier CID:# where # is a unique value that identifies each image (see 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 make this replacement?
Other important information is that I need to have in the code the information of which unique identifier replaced which value (image url) of the attribute src. For example, I need to have a way of knowing that the 354 identifier 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++;
}
The
src
the images are different?– Sam
I have no control over the content of srcs. So they can be equal or different
– Simone Xavier