You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
685 B

<?php
namespace Gregwar\Captcha;
/**
* Generates random phrase
*
* @author Gregwar <g.passault@gmail.com>
*/
class PhraseBuilder implements PhraseBuilderInterface
{
/**
* Generates random phrase of given length with given charset
*/
public function build($length = 5, $charset = 'abcdefghijklmnpqrstuvwxyz123456789')
{
$phrase = '';
$chars = str_split($charset);
for ($i = 0; $i < $length; $i++) {
$phrase .= $chars[array_rand($chars)];
}
return $phrase;
}
/**
* "Niceize" a code
*/
public function niceize($str)
{
return strtr(strtolower($str), '01', 'ol');
}
}