I have a text (html code) with many images like: 

`<img src="X" attributes />`

I need the *src* value to be replaced by a unique identification like **CID:#** where **#** is this unique value. I don't know if the src values will be all different, maybe some of them can be equal. 

Bellow is the code with the regular expression to match the images. Now, how to make the replacement?

PS: I need to store in a array the relation between the unique code created and the string that was replaced. For instance, i need to know that the 345 id is relative to the url "img/xxx.jpg".

```
preg_match_all('/<img src=[",\']([^>,^\',^"]*)[",\']([^>]*)/', $html, $matches);

$url_image = array();
$attr_image = array();
$cid = array();

foreach ($matches[1] as $i => $img){

    $url_image[$i] = $matches[2][$i];
    $attr_image[$i] = $matches[3][$i];

    //How to replace the src value with the value of $cid?
    $cid[$contador] = "CID:".date('YmdHms').'.'.time().$i;
}

```