Source for file Equation.php
Documentation is available at Equation.php
* Equation driver for Text_CAPTCHA.
* Returns simple equations as string, e.g. "9 - 2"
* @author Christian Weiske <cweiske@php.net>
* @author Christian Wenz <wenz@php.net>
require_once 'Text/CAPTCHA.php';
* Operators that may be used in the equation.
* Two numbers have to be filled in, and
* %s is needed since number2text conversion
* may be applied and strings filled in.
* Minimal number to use in an equation.
* Maximum number to use in an equation.
* Whether numbers shall be converted to text
* Complexity of the generated equations.
* 1 - simple ones such as "1 + 10"
* 2 - harder ones such as "(3-2)*(min(5,6))"
* @return true on success, PEAR_Error on error.
function init($options = array ()) {
if (isset ($options['min'])) {
$this->_min = (int) $options['min'];
if (isset ($options['max'])) {
$this->_max = (int) $options['max'];
if (isset ($options['numbersToText'])) {
if (isset ($options['severity'])) {
$this->_severity = (int) $options['severity'];
include_once 'Numbers/Words.php';
$this->_error = PEAR ::raiseError ('Number_Words package required', true );
* Create random CAPTCHA equation.
* This method creates a random equation. The equation is
* stored in $this->_equation, the solution in $this->_phrase.
* @return mixed true on success, PEAR_Error on error
$this->_error = PEAR ::raiseError ('Equation complexity of ' . $this->_severity . ' not supported', true );
* Creates a simple equation of type (number operator number)
* @return array Array with equation and solution
* Solves a simple equation with two given numbers
* and one operator as defined in $this->_operators.
* Also converts the numbers to words if required.
* @return array Array with equation and solution
$equation = sprintf($operator, $one, $two);
$code = '$solution=' . $equation . ';';
$equation = sprintf($operator, Numbers_Words ::toWords ($one), Numbers_Words ::toWords ($two));
return array ($equation, $solution);
* Return the solution to the equation.
* This method returns the CAPTCHA phrase, which is
* the solution to the equation.
* @return string secret phrase
* Creates the captcha. This method is a placeholder,
* since the equation is created in _createPhrase()
//is already done in _createPhrase();
* Returns the CAPTCHA (as a string)
}//class Text_CAPTCHA_Driver_TextEquation extends Text_CAPTCHA
Documentation generated on Mon, 11 Mar 2019 14:44:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|