Author Topic: Execute PHP in content  (Read 2794 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Execute PHP in content
« on: October 01, 2013, 10:11:58 PM »
I mainly run the content on one page for a site but the owner wants to be able to completely manage the page.  There are a few random PHP items like the price of a subscription that I currently embed via PHP so he can change it once via a config page and it is reflected everywhere.  But now that I'm storing the text for the page in the database, how can I force it to execute that PHP when displaying the blocks of the page??

To clarify, he puts in:

"the price is <?=$app->getSubscriptionPrice?>."

Right now it just prints that string as-is to the page.  I want that PHP call executed.  Is that possible??

By the way, I've goggled tons and come up empty so hopefully I'm missing something simple.

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: Execute PHP in content
« Reply #1 on: October 01, 2013, 10:30:02 PM »
Obviously read and think about all the potential security issues but: http://php.net/manual/en/function.eval.php

I would generally favor something like a template system over that thought.

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Re: Execute PHP in content
« Reply #2 on: October 01, 2013, 11:25:32 PM »
your time permitting, i agree with mike. templates stored in db is the way to go. avoid eval.

I've used mustache for a similar requirement. It's very simple, which is great,  and it has a PHP port.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Execute PHP in content
« Reply #3 on: October 02, 2013, 09:58:33 AM »
I would be more concerned about security if it was more than the owner using this and if anything was being submitted to this page.

I also tried using eval last night but I obviously was doing something wrong.