I want to replace different patterns in a string with the identical string. The replacements is an array with different values.
Since the pattern has to be mixed, I cannot find a solution. Also because preg_replace_all doesn't exist. Does anybody have an idea?
My code:
$artikelinhoud = $simpleXml->StandaardOplossing->attributes()->ArtikelInhoud;
$arrayImages = array();
preg_match_all('<!\[(CDATA)\[\s*(.*?)\s*\]\]>', $artikelinhoud, $arrayImages);
$images = array();
foreach ($arrayImages[2] as $key => $image) {
$images[$key] = 'src="data:image/jpg;base64,' . $image . '"';
}
$imagesOld = array();
$imagesOld[] = '/type="(.*?)"/';
$artikelinhoud = preg_replace($imagesOld, $images , $artikelinhoud);
So variable $imagesold is always the same. And $images is an array with different values to put between tags.
preg_replacereplaces already all occurances of the pattern. But propably you're interested in preg_replace_callback()preg_replace()you're very limited in replacement of the matched string. But usepreg_replace_callback()to have more possibillities.$imageslooks like. Does it contain$1that substitutes something for the capture group un$imagesOld?