# PHP - Variableninhalt ausführen.

**URL:** <https://forum.shopware.com/t/php-variableninhalt-ausfuhren/4665>\
**Category:** Shopware 3.5\
**Tags:** programming\
**Created:** [11. Oktober 2011 um 13:30 UTC](https://forum.shopware.com/t/php-variableninhalt-ausfuhren/4665 "2011-10-11T13:30:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [11. Oktober 2011 um 13:30 UTC](https://forum.shopware.com/t/php-variableninhalt-ausfuhren/4665/1 "2011-10-11T13:30:00Z")

</div>

Hey, ich stehe gerade auf dem Schlauch und komme nicht drauf. Ich habe in einer PHP Variable $code folgenden Inhalt: $code = ‚floor($roundprice / 0.1) \* 0.1 + 0.95‘; Dieser Inhalt kommt aus der DB und ist immer anders. Ich will nun diesen Code ausführen und das Ergebnis in eine Variable schreiben: ` eval("\$test = \"$code\";"); die($test); ` Fehler: syntax error, unexcepted T\_EXIT Weiß jmd den korrekten Syntax? Danke

---

<div class="post-metadata">

**Author:** ![Patrick\_Stahl](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/patrick_stahl/32/7679_2.png) [@Patrick\_Stahl](https://forum.shopware.com/u/Patrick_Stahl)\
**Post date:** [11. Oktober 2011 um 14:12 UTC](https://forum.shopware.com/t/php-variableninhalt-ausfuhren/4665/2 "2011-10-11T14:12:23Z")

</div>

Hallo, das Problem bei dir könnte sein, dass in $code einfach noch etwas fehlt, beispielsweise eine schliessende Klammer. Warum führst du nicht einfach einmal testweise eval($code); aus? Edit: Bei mir funktioniert es einwandfrei. Oder willst du das Ergebniss in $test speichern? Das müsstest du, wenn ich mich nicht irre, mittels eines returns in $code machen, und dieses dann außerhalb von eval in eine Variable speichern. `$code = "return '3';"; $test = eval($code); die($test);` Gruß, Patrick :shopware:

---

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [11. Oktober 2011 um 15:49 UTC](https://forum.shopware.com/t/php-variableninhalt-ausfuhren/4665/3 "2011-10-11T15:49:24Z")

</div>

Ich wollte das Ergebnis in $test speichern. Aber habe es nun hinbekommen. Danke ` //FORMEL AUSFÜHREN $todo = str\_replace('PRICE','$price',str\_replace('ROUNDMATH','round',str\_replace('ROUNDDOWN','floor',$under\_rule['formel']))); eval(" \$price2 = $todo;"); ` In $price2 steht nun das Ergebnis 🙂
