Convert a string to a variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stdq
    New Member
    • Apr 2013
    • 94

    Convert a string to a variable

    Hi, everyone. So, suppose I have a variable holding a string, like

    Code:
    $var = "ln(x)";
    I wanna be able to numerically integrate that string - I wanna be able to, inside a for statement, calculate ln(x) for some values of x. How do I make PHP understand the value of the string as a statement? Thanks in advance!
  • stdq
    New Member
    • Apr 2013
    • 94

    #2
    Nevermind, achieved that using eval. Thanks again!

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Be careful with eval. If you are allowing a client to determine what goes into that eval, they can do a lot of harm to your server by running any code they want.

      Comment

      • stdq
        New Member
        • Apr 2013
        • 94

        #4
        Thanks! I guess then I will have to remove a functionality from my website. Is there another option?

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          That depends on what you actually want to do. If you just want return ln from an input number, then there's no need to use eval, you can just call the function directly.

          Comment

          Working...