Jump to content

Recommended Posts

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.