kr1pt Posted May 25, 2011 Share Posted May 25, 2011 Hello everyone. I'm new so I'm still reading the rules, but... I have a couple scripts, libraries and other PHP apps on my PC, and those scripts are just collecting dust on PC so I will post some of them in here. Please comment scripts Pretty good for 15 years old kid? :$ Summation function: <?php /** * Summation of m numbers * * @param integer $m * @param integer $n * @param string $parameter Terms of summation * @param string $parameter_delimiter * @return integer */ function sum($m = 0, $n = 1, $parameter = 'n', $parameter_delimiter = 'n') { if ($m === 0 or is_numeric($m) === FALSE) { return 0; } if ($n == 0 or is_numeric($n) === FALSE) { $n = 1; } if ($parameter == '' or is_numeric($parameter) === TRUE) { $parameter = 'n'; } if ($parameter_delimiter == '' or is_numeric($parameter_delimiter) === TRUE or strlen($parameter_delimiter) > 1) { $parameter_delimiter = 'n'; } $result = 0; for ($x = 1; $x <= $m; $x++) { $i = $x * $n; $param = str_replace($parameter_delimiter, $i, $parameter); $result += eval('return ' . $param . ';'); } return (int)$result; } // example: // (1+1) + (2+1) + (3+1) + (4+1) + (5+1) echo sum(5, 1, 'n+1'); // example 2: // (2+1) + (4+1) + (6+1) + (8+1) + (10+1) echo sum(5, 2, 'n+1'); // you can also use n/2, n*sqrt(2) or other... PHP form validation library-class: http://www.2shared.com/file/7v2IzMfM/Form.html Everything is explained in index.php, such as configuration and stuff. Still working on security in that class. Quote Link to comment https://forums.phpfreaks.com/topic/237469-form-validation-class-and-summation-function/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.