PHP-Code aus DB

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

  • PHP-Code aus DB

    tag.

    hab ein kommpliziertes problem:

    und zwar lese ich php-code aus einer db aus und will ihn dann an den client ausgeben. wie kann ich den code vorher noch parsen? schon probiert: in temporäre datei schreiben, diese datei dan mit include einbinden... is aber ziemlich sch* -- braucht viel leistung, is unsicher...


    weiss irgendwer was in der richtung?

  • #2
    http://www.php.net/manual/de/function.eval.php

    mixed eval ( string code_str)

    eval() versucht, den in code_str enthaltenen String als PHP-Code auszuführen. Abgesehen von anderen Zwecken kann dies nützlich sein, um Code auszuführen, der aus einer Datenbank ausgelesen wird.

    mehr im Link

    gruss

    Comment


    • #3
      danke.

      war supa, die hilfe...

      eigentlich kenn ich eval eh, habs auch scho verwendet, aber irgendwie war das ein blackout.


      auf jeden fall vielen dank...

      Comment


      • #4
        Also mal theoretisch gefragt:

        Sieht mein Code dann nachher so aus?

        PHP Code:
        eval( echo "Hallo!"; ); 
        Oder wie?
        Last edited by TobiaZ; 08-04-2002, 19:52.

        Comment


        • #5
          ja theoritisch schon, mal abgesehen davon, dass du das ganze noch in anführungszeichen setztn musst und die sonstigen a. escapen...

          also etwa:

          eval("echo \"hallo\";");


          aber du kannst natürlich auch eine variable nehmen:


          $ausgabe="echo(\"hallo\");";
          eval($ausgabe);


          mfG

          Christoph

          Comment


          • #6
            THX!

            Comment


            • #7
              geht doch nicht....

              wartet mal.

              ich hab das mit eval() jetz ausprobiert, aber das geht nicht...

              ich glaub es liegt dran, dass das ganze nicht reiner php-code is, sondern wie in einer normalen php-datei in den html-code reingemixt.

              hat irgendeiner eine idee, wie ma das lösen könnte?

              danke im voraus...

              Comment


              • #8
                schon gefunden:



                ::::::::::::::::::::[von php.net aus dem manual]::::::::::::::::::::


                If you are trying to eval() somehthing which is a fully-formed PHP file,
                you will need to prepend '?>' to the string. For example, if you have
                a script mypage.php which loads example.php and evaluate it:

                --- file: example.php ---
                <?php phpinfo(); ?>

                --- file: mypage.php ---
                <?php
                $string = implode ('', @file('example.php'));
                // Massage the contents of $string however you want.
                eval ('?>' . $string);
                ?>



                09-Jan-2002 09:13

                The previous comment would imply to me that you must also add '<?php'
                after $string in the eval function, so that your original file may
                continue with additional php code after the eval()

                So...

                --- file: example.php ---
                <?php phpinfo(); ?>

                --- file: mypage.php ---
                <?php
                $string = implode ('', @file('example.php'));
                // Massage the contents of $string however you want.
                eval ('?>' . $string . '<?php');
                // Additional code continues...
                $allWorldProblems = "cured";
                ... etc
                ?>


                :::::::::::::::::

                Comment

                Working...
                X