Reply to RE: [PHP] Mathmatical formula

Your name:

Reply:


Posted by Jay Blanchard on 12/20/05 22:34

[snip]
I have an application that allows the users to input a formula:
(Width*Height)/144

This formula gets updated with a part's specific width & height and
actually returns:

(36.00000*58.00000)/144

I use preg_replace to replace Width and Height with values from the
following array:

[Width] => 36.00000
[Height] => 58.00000

How can I get the resulting formula to actually calculate?
Simplified version of my code:

$partFormula = '(Width*Height)/144';
$prof = array('Width'=>36,'Height'=>58);

$find = array();
$replace = array();

foreach($prof AS $key => $val){
array_push($find,"[$key]");
array_push($replace,$val);
}
return preg_replace($find,$replace,$partFormula);
//returns (36.00000*58.00000)/144

eval() doesn't seem to do much for me (parse error, unexpected $end).
[/snip]

Try;

$foo = preg_replace($find,$replace,$partFormula);
return $foo

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация