[Variablen] Variablenname als Inhalt einer "anderen" Variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Variablen] Variablenname als Inhalt einer "anderen" Variable

    Hallo an alle,

    ich habe da ein kleines Problem mit PHP:

    Ich will eine Variable nutzen, um eine andere Variable auszugeben:

    (img0="bild.jpg" - img1="bild1.jpg" usw. werden per http übergeben)
    (anz ist ebenfalls eine Variable die per http übergeben wird und
    gibt die anzahl der Bilder an, die übertragen werden)

    http://www.test.de/images.php?anz=1&...img1=bild1.jpg

    PHP Code:
    $i 0;
    $pre "img";

    while (
    $i<$anz) {

    $temp $pre.$i;

    echo(
    "<img src=$$temp border=1>&nbsp;&nbsp;");

    $i++;

    - Im Resultat kommt ein HTmlcode raus, indem das Bild img0 geladen
    wird -> <img src=$img0 border=0>

    Es soll aber der "inhalt" der Variable $img0 rauskommen, also
    <img src=bild.jpg border=0>.

    Was fehlt - was mach ich blos falsch?

    bitte helft mir !!!


    EDIT:
    php.tags by Abraxax
    Last edited by Abraxax; 12-08-2003, 10:47.

  • #2
    ich hoffe mal, dass ich dein problem verstanden habe......

    teste es mal so....
    PHP Code:
    $i 0;
    $pre "img";

    while (
    $i<$anz)
    {
        
    $temp = ;
        echo(
    "<img src=".$pre.$i." border=1>");
        
    $i++;

    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


    Comment


    • #3
      ... danke für die Idee...

      aber leider kommt das gleiche Ergebnis

      <img src=img0 border=1>

      -> in der Varialbe img0 ist der Wert "bild.jpg" hinterlegt <-
      dieser Inhalt möchte ich dort hin haben....????

      hope for help


      Comment


      • #4
        ok. ich gehe davon aus, dass du $img0 woanders hast definiert, weshalb du mich sozusagen auf die falsche fährte geleitet hast.....

        dann teste das mal so.... (ist aber fast das gleiche, wie das von dir)

        PHP Code:
        $i 0;
        $pre "img";

        while (
        $i<$anz)
        {
            
        $temp = ;
            echo(
        "<img src=".${$pre.$i}." border=1>");
            
        $i++;

        INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


        Comment


        • #5
          Klassseee......

          super - das funzt

          ...nur die Punkte sind nicht notwendig - also

          <img src='${$pre.$i}' border=1>

          geht.

          Vielen Dank! Auf die Klammer währe ich wohl NIIEEE gekommen ;-)

          Comment


          • #6
            die punkte mache immer, weil es sauberer ist, als einfach eine var in den string zu schreiben.

            und deine variante hätte damit wahrscheinlich auch funktioniert.

            teste es mal aus.
            PHP Code:
            echo("<img src=".$$temp." border=1>&nbsp;&nbsp;"); 
            INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


            Comment


            • #7
              ..ja das funzt zwar nur
              im HTmL habe ich dann dummerweise die Punkte - deshalb wollte/muß
              ich sie weglassen
              <img src=".bild1.jpg." border=1>

              Gruß Oli

              Comment


              • #8
                im html hat man keine punkte, wenn man es richtig macht...


                aber hauptsache es funktioniert...
                INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                Comment

                Working...
                X