Self modifying code? From stuff the user enters? Watch PHP crash and burn.
Yes, you could use eval() to execute the string as code, but by the time you've checked it out safely enough you might as well just parse it yourself. A recursive-descent parser wouldn't be that hard to write in PHP, and is certainly adequate for simple mathematical formulae.