Jump to content

skullJ

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

skullJ's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. OK! mjdamato's example working... so many thank you guys!!!!!!
  2. User inserts names and values of variables. User uploads an .srt file with simple C lang with mathematical actions and script returns an array with variables' names and values. For example: input can be: l1 = 100 l2 = 200 x = SQR(l1^2 + l2^2) and output should be: Array ( [l1] => 100 [l2] => 200 [xb] => 226,7)
  3. Here it is an example using the str_replace: <?php $variables['x'] = 60; $variables['y'] = 30; $variables['xb'] = 100; $variables['yb'] = 50; $variables['D'] = 25; $example1 = "(x ^ 2 + y ^ 2) / 2"; $example2 = "((2 * yb) + SQR(D)) / (2 * (xb ^ 2 + yb ^ 2))"; foreach($variables as $key => $value) { $example1 = str_replace($key, $value, $example1); $example2 = str_replace($key, $value, $example2); } // Echo: (60 ^ 2 + 30 ^ 2) / 2 echo $example1; // Echo: ((2 * 30b) + SQR(25)) / (2 * (60b ^ 2 + 30b ^ 2)) echo $example2; ?> Ofcourse the 2nd example is wrong! The result should echo this "((2 * 30) + SQR(25)) / (2 * (60 ^ 2 + 30 ^ 2))" The list of ALL the math functions that should not be replaced is this "sin, cos,tan, asin, acos, SQR, ATN, atan, ABS, exp, log, ln, mod, div pi, e". Multiply steps sounds bad, but i really wana see your thought (if you can spend your time to this).
  4. Iam sory... All i want is to replace c. yb, D, xb, yb, with numbers. I dont know if variable c is a lowercase letter or C, because user insert this code. If you see my example in previous post, you will understand how i wanna use it! ((2 * c * yb) + SQR(D)) / (2 * (xb ^ 2 + yb ^ 2)) The SQR(D) is the biggest problem, and this is what i cant replace. Maybe SQR can used in pattern? The second problem is that can be yb and yb1 or yba ... As I say i think i should use preg_replace to replace all alphanumeric ( [a-zA-Z0-9] ) between math symbols or parentheses ( "+-/*^()" ) and I dont want to replace the SQR, ATN, ABS, pi and e (like [^ABS|SQR|ATN|ABS|pi|e] ).
  5. Hi, I need to replace all alphanumerics variables from quote below, with numbers, using preg_replace c = (l1 ^ 2 - l2 ^ 2 + xb ^ 2 + yb ^ 2) / 2 ya1 = ((2 * c * yb) + SQR(D)) / (2 * (xb ^ 2 + yb ^ 2)) Here it is an example (using str_replace) of what i want to do: <?php include('RPN.php'); function do_maths($expr){ global $variables; foreach($variables as $key => $value) { $expr = str_replace($key, $value, $expr); } $rpn = new Math_Rpn(); $result = $rpn->calculate($expr,'deg',false); return $result; } $variables['l1'] = 100; $variables['l2'] = 50; $variables['x'] = 60; $variables['y'] = 30; $phrase = "c = (l1 ^ 2 - l2 ^ 2 + x ^ 2 + y ^ 2) / 2"; $phrase = explode('=',$phrase); $result = do_maths($phrase[1]); echo $result; // the result is 6000 ?> Thank you
  6. Did I post it in wrong section? Or nobody can help?
  7. As I posted here i need a pattern to replace all alphanumerics only between spaces, math symbols ( +-*/^), parentheses ( )and allready math fuctions like ABS, ATN, SQR, e, pi . examples: c = (l1 ^ 2 - l2 ^ 2 + xb ^ 2 + yb ^ 2) / 2 ya1 = ((2 * c * yb) + SQR(D)) / (2 * (xb ^ 2 + yb ^ 2)) Any help?
  8. RPN is working! This is my first example with RPN: <?php include('RPN.php'); function do_maths($expr){ global $variables; foreach($variables as $key => $value) { $expr = str_replace($key, $value, $expr); } $rpn = new Math_Rpn(); $result = $rpn->calculate($expr,'deg',false); return $result; } $variables['l1'] = 100; $variables['l2'] = 50; $variables['x'] = 60; $variables['y'] = 30; $phrase = "c = (l1 ^ 2 - l2 ^ 2 + x ^ 2 + y ^ 2) / 2"; $phrase = explode('=',$phrase); $result = do_maths($phrase[1]); echo $result; // the result is 6000 ?> But i really dont have luck with patterns and im using str_replace. Can anyone help me with pattern?
  9. What libraries? Can you explain this to me?
  10. that's exactly is that iam afraid of!!!! Im already searching for patterns...and i hate them
  11. so you propose to preg_replace the variables into numbers and then make maths with eval. Right?
  12. Im working on univercity project and a part of my script is to calculate some maths. All I need is to input varables into array and a mathematical action, and get the resolt as output. For example: <?php $variables['l1'] = 100; $variables['l2'] = 50; $variables['x'] = 60; $variables['y'] = 30; $phrase = "c = (l1 ^ 2 - l2 ^ 2 + x ^ 2 + y ^ 2) / 2"; $result = do_maths($phrase); echo $result; // the result is 6000 php?> I have some ideas and i can show you some code but all these drives me on deadend!
  13. sory i cant understand! :( can someone write the right code? :-\
  14. hmmm...so the edit part of mine first post should be looks like: [code]if($submit)   { $music= $_POST['music']; $result = mysql_query("UPDATE musictable SET music='$music' WHERE id='$id' ",$connect); } elseif($id) { $result = mysql_query("SELECT * FROM musictable WHERE id='$id' ",$connect); while($myrow = mysql_fetch_assoc($result))              {              if(isset($_POST['nonhtml']))  $music = $myrow['music']; Enable music:<input type="checkbox" name="music" value="on" <?php isset($_POST['music'] ? 'checked="checked" ':' '?>/><br> }[/code] Am I right? And i have a second quetion...what kind of values can be in 'music'!I can use "on" and "off" or simply "1"? Thank u!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.