Ankündigung

Einklappen
Keine Ankündigung bisher.

Variable in echo-Befehl?

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Variable in echo-Befehl?

    Hi!

    Also ich glaub ich werd hier bald verrückt. Ich habe folgenden Echobefehl:

    echo "<img src=\"images/balken/balken'$fid'_l.gif\" height=\"10\">";

    Das Problem ist der Bereich '$fid'. Die Variable heißt $fid. Mein Problem ist es jetzt, wie ich die dort einsetzte. Also mit '' geht es nicht, lass ich die weg, geht es auch nicht. Mit '..' geht es auch nicht. Wie bekomme ich die Variable dort rein, also $fid ist einfach nur eine Zahl zwischen 1 und 10. Rauskommen soll eben sowas:

    images/balken/balken5_l.gif

  • #2
    PHP-Code:
    [img]images/balken/balken<?php echo $fid?>_l.gif[/img]
    alternativ:

    PHP-Code:
    <?php
    echo "<img src=\"images/balken/balken".$fid."_l.gif\" height=\"10\">"
    ?>
    mfg

    Kommentar


    • #3
      Deine Variable heißt $fid?
      Für php wäre aber auch $fid_l ein gltiger Name, also benutzt es ihn ohne weitere Markierung.
      Wie finde ich das im Handbuch
      manual => types => strings double quoted strings => string parsing => Complex (curly) syntax
      http://www.php.net/manual/en/languag...string.parsing
      This isn't called complex because the syntax is complex, but because you can include complex expressions this way.

      In fact, you can include any value that is in the namespace in strings with this syntax. You simply write the expression the same way as you would outside the string, and then include it in { and }. Since you can't escape '{', this syntax will only be recognised when the $ is immediately following the {. (Use "{\$" or "\{$" to get a literal "{$"). Some examples to make it clear:

      PHP-Code:
      <?php
      $fid 
      '123';
      echo 
      "<img src=\"images/balken/balken{$fid}_l.gif\" height=\"10\">"
      ?>

      Kommentar


      • #4
        Zitat von Bruchpilot
        Deine Variable heißt $fid?
        Für php wäre aber auch $fid_l ein gltiger Name, also benutzt es ihn ohne weitere Markierung.
        Ja, genau das war mein Problem, also er hat eben das _l mit in die Variabele genommen und ich wusste nicht, wie ich es eben abgrenzen kann. Aber danke, mit dem {} geht es.

        Kommentar

        Lädt...
        X