eval + str_replace calculate formulas

<?php
$replaces = array(‘$a’, ‘$b’);
$with = array(2, 4);
$formula = “return (($a * $a) + ($b * $b));”;
$formula = str_replace($replaces, $with, $formula);

echo eval($formula);
?>

Post a comment or leave a trackback: Trackback URL.

Вашият коментар

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Промяна )

Twitter picture

You are commenting using your Twitter account. Log Out / Промяна )

Facebook photo

You are commenting using your Facebook account. Log Out / Промяна )

Connecting to %s

Follow

Get every new post delivered to your Inbox.