Hallo,
Mit assoziativen Arrays kenne ich mich nicht so aus. Ich jedenfalls hätte es mit einem mehrdimensionalen Array versucht.
$images = array(array("%sm63%","BILDQUELLE"),array("%sm64%","BILDQUELLE"),...)
>
> und dementsprechend auch die for- oder foreach-Schleife:
>
> ~~~php
> foreach($x;$x<count($images);$x++)
> {
>
> if(strpos($text,$images[$x][0]))
> {
> str_replace($images[$x][0],$images[$x][1],$text);
> }
>
> }
>
Wie gesagt, dynamisches Befüllen des Arrays müsste davor erfolgen.
Das ist IMHO Overkill (warum strpos verwenden, warum str_replace n mal anwenden, wenn einmal reicht?) - und funktioniert zudem nicht (unabhängig von der foreach-Geschichte), da strpos auch 0 als gültigen Index zurückliefern kann und außerdem musst Du mit dem Rückgabewert von str_replace auch was anfangen.
Folgndes ist IMHO *viel* einfacher, klarer und verständlicher:
$ersetzungen = array(
'%smf63%' => 'bla...',
'%smf64%' => 'blub...'
);
$text = str_replace (array_keys ($ersetzungen), array_values ($ersetzungen), $text);
Viele Grüße,
Christian
--
"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." - Bjarne Stroustrup
"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." - Bjarne Stroustrup