Counter gibt Grafiken nicht aus.

  • Counter gibt Grafiken nicht aus.

    Hallo. Ich hab ein Problem mit meinem Counter. Er zeigt mir einfach die Grafiken von 1 bis 5 nicht an. Von 6 bis 0 ist alles in Ordnung. Wenn ich mit den Quelltext ansehe, dann steht da bei der Countzahl 16 folgendes:

    Quellcode

    1. <img src="images/<img src="images/6/6.gif">/1.gif"><img src="images/6/6.gif">


    Warum fügt er die "<img src"images/" bei den Zahlen 1 bis 5 hinzu? Bei den anderen klappts weunderbar. Hab auch schon versucht die Hochkommata als Sonderzeichen zu deklarieren ('<img src=\"images/6/1.gif\">') oder anstatt Zahlen Buchstaben für die Dateinamen und Verzeichisse angegeben. Alles nichts geholfen.

    Hier der Code:

    Quellcode

    1. <?
    2. $countfile = 'data/count.mtd';
    3. $handle = fopen($countfile, 'r+');
    4. $count = fgets($handle, 10);
    5. $art = 1;
    6. // Textcounter
    7. if($art == 0) {
    8. echo $count;
    9. } else {
    10. // Grafikzähler
    11. $count = ereg_replace('1', '<img src="images/6/1.gif">', $count);
    12. $count = ereg_replace('2', '<img src="images/6/2.gif">', $count);
    13. $count = ereg_replace('3', '<img src="images/6/3.gif">', $count);
    14. $count = ereg_replace('4', '<img src="images/6/4.gif">', $count);
    15. $count = ereg_replace('5', '<img src="images/6/5.gif">', $count);
    16. $count = ereg_replace('6', '<img src="images/6/6.gif">', $count);
    17. $count = ereg_replace('7', '<img src="images/6/7.gif">', $count);
    18. $count = ereg_replace('8', '<img src="images/6/8.gif">', $count);
    19. $count = ereg_replace('9', '<img src="images/6/9.gif">', $count);
    20. $count = ereg_replace('0', '<img src="images/6/0.gif">', $count);
    21. echo $count;
    22. }
    23. ?>
    Alles anzeigen
  • das Ersetzen läuft sequenitell ab.

    "test 1 test test test" -> ersetzte 1 durch {img2/1}
    "test {img2/1} test test test" -> ersetzte 2 durch {img2/2}
    "test {img{img2/2}/1} test test test"

    Beispiel:

    Quellcode

    1. <?php
    2. $zahl = '1';
    3. $zahl = str_replace(1,'{1}',$zahl);
    4. $zahl = str_replace(1,'{1}',$zahl);
    5. $zahl = str_replace(1,'{1}',$zahl);
    6. $zahl = str_replace(1,'{1}',$zahl);
    7. echo $zahl;
    8. //Output = {{{{1}}}}
    9. ?>


    wenn Ordner- und Dateinamen keine Zahlen enthalten würde, hätte es funktioniert.

    Tip: Mit [phpdoc]str_replace[/phpdoc] kannst du Arrays als Parameter übergeben:

    Quellcode

    1. <?php
    2. $zahl = '12113';
    3. echo str_replace(
    4. array(1,2,3,4,5,6,7,8,9,0),
    5. array('{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{0}'),
    6. $zahl);
    7. //Ausgabe: {1}{2}{1}{1}{3}
    8. ?>