Hallo ich bin mit meinem Problem ein ganzes Stück weiter gekommen
Allerdings gibt diese Funktion eine Fehlermeldung aus
Compilation failed: nothing to repeat at offset 0
Ausgabe von Print_R $array_to_substitute
Array ( [0] => /#/ [1] => /#/ [2] => /+/ [3] => /+/ ) 1
Ausgabe von PRINT_R $array_to_substitute
Array ( [0] => [1] => [2] => [3] => ) 1 und die entsprechenden leeren bilder
Was mache ich da falsch (# kommt zweimal vor, + zweimal)
Hinweis Raute werden ersetzt das pluszeichen nicht.
Hier die Funktion:
Allerdings gibt diese Funktion eine Fehlermeldung aus
Compilation failed: nothing to repeat at offset 0
Ausgabe von Print_R $array_to_substitute
Array ( [0] => /#/ [1] => /#/ [2] => /+/ [3] => /+/ ) 1
Ausgabe von PRINT_R $array_to_substitute
Array ( [0] => [1] => [2] => [3] => ) 1 und die entsprechenden leeren bilder
Was mache ich da falsch (# kommt zweimal vor, + zweimal)
Hinweis Raute werden ersetzt das pluszeichen nicht.
Hier die Funktion:
PHP Code:
function positionierung($text, $bilder) {
$zahl_raute = substr_count($text, "#"); //wie oft ist ein zeichen vorhanden
$zahl_plus = substr_count($text, "+");
$zahl = $zahl_raute + $zahl_plus;
$raute = Array();
$plus = Array();
$image_for_raute = Array();
$image_for_plus = Array();
$offset = 0;
for($i=0; $i<$zahl_raute; $i++) //zeichenpositionien bestimmten
{
$raute[$i] = "/#/";
$image_for_raute[$i] = "<img>";
}
$offset= 0;
for($i=$zahl_raute; $i<$zahl; $i++) //zeichenpositionien bestimmten
{
$plus[$i] = "/+/";
$image_for_plus[$i] = "<img>";
}
//sortieren und zusammenfassen
$array_for_substitute = Array();
foreach ($image_for_raute as $key => $value)
$array_for_substitute[$key] = $value;
foreach ($image_for_plus as $key => $value)
$array_for_substitute[$key] = $value;
$array_to_substitute = Array();
foreach ($raute as $key => $value)
$array_to_substitute[$key] = $value;
foreach ($plus as $key => $value)
$array_to_substitute[$key] = $value;
return preg_replace($array_to_substitute, $array_for_substitute, $text);
}
Comment