Jump to content


Urgent Help Needed! Plz help!


4 replies to this topic

#1 Kokkei Mizu

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 13 March 2006 - 09:52 PM

I have a large Math equation in a string. How can I get PHP to calculate it?

eg.: The string is something like this:

45+32-5/8*55

How? Thanks!

#2 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 13 March 2006 - 10:08 PM

well lets see here...

<?
echo 45+32-5/8*55;
?>

Edited by coolaid, 13 March 2006 - 10:08 PM.


#3 Kokkei Mizu

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 13 March 2006 - 10:14 PM

but i have the string in a variable. and if i just go

echo $string;

it would echo it without calculating it...

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 13 March 2006 - 11:28 PM

Other then some huge parsing class, the easiest thing i can think to do would be to use eval().
<?
eval('echo '.$string.';');
?>


#5 Kokkei Mizu

    Young Padawan

  • Members
  • Pip
  • 3 posts

Posted 14 March 2006 - 06:30 PM

works great! thanks ^_^

Edited by Kokkei Mizu, 14 March 2006 - 06:31 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users