PHP code example of zyan / beautiful

1. Go to this page and download the library: Download zyan/beautiful library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zyan / beautiful example snippets


use Zyan\beautiful\beautiful;

Beautiful::go('15912345678');



Beautiful::config(
    ['靓号规则 比如 AAAA AABB ABCD...'],
    ['处理类型: mobile为手机号(只取后8位) 不传为通用,也就是对输入源不作任何处理']
);

//合并默认配置规则 也就是默认的规则上加上新的规则
Beautiful::config(['AAAA','AAABBB','AABB'],['mobile']);

//重新设置新规则 会复盖默认的规则
Beautiful::setConfig(['AAAA','AAABBB','AABB'],['mobile']);

//获取当前全局配置
Beautiful::getConfig();

//以上都是全局配置
//如果某对某一次的检测单独设置请传入到后面
Beautiful::go('15912345678',['AAAA','AAABBB','AABB'],['mobile']);


Beautiful::go('15912345678');
// ['ABCDEF'] 
 
namespace Zyan\Beautiful\Rules;


use Zyan\Beautiful\RulesInterface;

/**
 * Class ABCDEF.
 *
 * @package Zyan\Beautiful\Rules
 *
 * @author 读心印 <[email protected]>
 */
class ABCDEF implements RulesInterface
{
    public static function go(string $str): bool
    {
        $isMatched = preg_match_all('/^\d(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)|9(?=0)){5,})\d/m', $str, $matches);
        return $isMatched>0 ? true : false;
    }
}
 
Beautiful::setRules('ABCDEF',Zyan/Beautiful/Rules/ABCDEF:class); //这个class取决于您的命名空间

Beautiful::go('15912345678',['ABCDEF']); //全局配置请用 Beautiful::Config(['ABCDEF'])
// ['ABCDEF']