# Snippet · Mecha CMS

Code snippet collection for developers.

Author: Taufik Nurrohman · 513 Views

Tweet

Playing around with the math captcha.

### Unicode

Using unicode characters to customize the number appearance:

``````// → ❷ ➕ ❶
1 => '&#x2776;',
2 => '&#x2777;',
3 => '&#x2778;',
4 => '&#x2779;',
5 => '&#x277A;',
6 => '&#x277B;',
7 => '&#x277C;',
8 => '&#x277D;',
9 => '&#x277E;',
10 => '&#x277F;',
'+' => '&#x2795;',
'-' => '&#x2796;'
]);``````
``````// → ➇ ➖ ➅
1 => '&#x2780;',
2 => '&#x2781;',
3 => '&#x2782;',
4 => '&#x2783;',
5 => '&#x2784;',
6 => '&#x2785;',
7 => '&#x2786;',
8 => '&#x2787;',
9 => '&#x2788;',
10 => '&#x2789;',
'+' => '&#x2795;',
'-' => '&#x2796;'
]);``````
``````// → ➌ ➕ ➎
1 => '&#x278A;',
2 => '&#x278B;',
3 => '&#x278C;',
4 => '&#x278D;',
5 => '&#x278E;',
6 => '&#x278F;',
7 => '&#x2790;',
8 => '&#x2791;',
9 => '&#x2792;',
10 => '&#x2793;',
'+' => '&#x2795;',
'-' => '&#x2796;'
]);``````

### Image

Using images to customize the number appearance:

``````echo Captcha::math(1, 10, [
1 => '<img src="one.gif">',
2 => '<img src="two.gif">',
3 => '<img src="three.gif">',
4 => '<img src="four.gif">',
5 => '<img src="five.gif">',
6 => '<img src="six.gif">',
7 => '<img src="seven.gif">',
8 => '<img src="eight.gif">',
9 => '<img src="nine.gif">',
10 => '<img src="ten.gif">',
'+' => '<img src="plus.gif">',
'-' => '<img src="minus.gif">'
]);``````

### Random

Random output:

``````echo Captcha::math(1, 5, [
1 => array_rand([1, 'one', '&#x2776;', '<img src="one.gif">']),
2 => array_rand([2, 'two', '&#x2777;', '<img src="two.gif">']),
3 => array_rand([3, 'three', '&#x2778;', '<img src="three.gif">']),
4 => array_rand([4, 'four', '&#x2779;', '<img src="four.gif">']),
5 => array_rand([5, 'five', '&#x277A;', '<img src="five.gif">']),
'+' => array_rand(['+', 'plus', '&#x2795;', '<img src="plus.gif">']),
'-' => array_rand(['-', 'minus', '&#x2796;', '<img src="minus.gif">'])
]);``````

### Fake Operator

Fake math operator:

``````echo Captcha::math(1, 3, [
1 => '5 + 3 - 7',
2 => '(4 / 2)',
3 => '12 - 9',
'+' => '+',
'-' => '-'
]);``````