I have got multidimensional array (name + image path), where some names are similar, like:
array("name" => "OpenGL", "img" => "OpenGL.png"),
array("name" => "OpenGL Lighting ( Advanced )", "img" => "OpenGL-LightingAdvanced.png")
then I replace names with images.
foreach ($extensions as $extension) {
$ret=str_ireplace($extension['name'],'<img src="images/'.$extension['img'].'" alt="'.$extension['name'].'" />: ',$ret);
}
It works as long as array is sorted from shortest name to longest one, but in that case, longer names will never be changed, eg. OpenGL Lighting ( Advanced ) will be
<img src="images/OpenGL.png" alt="OpenGL" /></div>: Lighting ( Advanced )
When I sort it from longes name to shortest one it is even worse, couse it will change name in src:
<img src="images/<img src="images/OpenGL.png" alt="OpenGL" />: -LightingAdvanced.png" alt="<img src="images/OpenGL.png" alt="OpenGL" />: Lighting ( Advanced )" />:
My only idea is to check if there isn't src="images/ or alt=" before name, if so - replace, but I have no idea how can I easily do.