PHP code example of yll1024335892 / phptools

1. Go to this page and download the library: Download yll1024335892/phptools 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/ */

    

yll1024335892 / phptools example snippets



use Yll1024335892\Phptools\UploadClass;
class indexController{
    public function index(){
        //提交比对
        if(!empty($_FILES['filename'])){
            $uper = new UploadClass('filename', 'upload', '2.png');
            $uploadedFile = $uper->upload();
            if($uploadedFile){
                echo '上传文件路径 : '.$uploadedFile;
            }else{
                echo $uper->error;
            }
        }
    }
}
//html表单
<form action="" method="post" enctype="multipart/form-data">
    <input type="file" name="filename" value="" />
    <input type="submit" id="" value="提交" />
</form>


use Yll1024335892\Phptools\VerifyCodeClass;
class indexController{
    public function index(){
        //提交比对
        if(PG_POST){
            //比对验证码
            if($_POST['yzm'] != getSession('pgVcode')){
                echo '验证码错误';
            }else{
                echo '验证码正确';
            }
        }
    }

    //绘制验证码
    public function vcode(){
        /*
         * verifyCode 参数
         * 1、图片宽度
         * 2、图片高度
         * 3、字符总数
         * 4、包含数字的数量
         * 5、字体【可省参数 默认:AMBROSIA.ttf,如需更换请将字体文件部署到 src/temp/fonts 文件夹下】
         */
        $vcode = new VerifyCodeClass(88, 32, 4, 1);
        /*
         * 可修改属性
        $vcode->bgcolor   = array(255, 0, 0); //验证码背景颜色
        $vcode->codeColor = array(0, 255, 0); //验证码文本颜色
        $vcode->fontSize  = 30; //验证码文字大小
        $vcode->noise     = false; //是否绘制干扰字符
        $vcode->noiseNumber = 10; //干扰字符数量
        $vcode->sessionName  = 'yourname'; //保存验证码的 session 名称
        */
        //绘制验证码
        $vcode->draw();
    }
}

利用视图展示验证码,提交 POST 数据
<html>
<head>
<title></title>
</head>
<body>
<form action="" method="post">
    验证码 : <br />
    <input type="text" name="yzm" /><img src="/index/vcode" onclick="changeVcode(this);" /><br />
    <input type="submit" id="" value="提交" />
</form>
<script type="text/javascript">
//点击更换验证码
function changeVcode(vcodeImg){
    vcodeImg.setAttribute('src', '/index/vcode/' + Math.random());
}
</script>
</body>
</html>


$md5 = new Md5Class();
$str = 'yll1024335892';
echo $md5->toMd5($str).'<br />';
echo $md5->getMd5('94478811d37e11a7ace56c5503174b2dce19');


use namespace Yll1024335892\Phptools\ServerClass;
class indexController{
    public function index(){
        $serverInfo = ServerClass::info();
	p($serverInfo);
    }
}


use Yll1024335892\Phptools\CurlClass;
class indexController{
    public function index(){
        $curl = new CurlClass();
        $res  = $curl->get('http://api.hcoder.net');
        //返回结果
        echo $res;
    }
}


use Yll1024335892\Phptools\CurlClass;
class indexController{
    public function index(){
        $curl = new CurlClass();
        //post 数据
        $data = array('name' => 'grace', 'age' => 10);
        $res  = $curl->post('http://api.hcoder.net', $data);
        //curl 状态
        p($curl->http_status);
        //传输时间毫秒
        echo $curl->speed;
        //返回结果
        echo $res;
    }
}


use Yll1024335892\Phptools\DownloadClass;
class indexController{
    public function index(){
        //不设置下载文件名
        DownloadClass::download('index.php');
        //设置下载文件名
        DownloadClass::download('index.php', '2.php');
    }
}

参数:

1、xml 数据【数组或字符串格式】
数组格式:
$data = array(
    array('nodeName' => 'person', 'key' => 'value', 'key' => 'value'),
    array('nodeName' => 'person', 'name' => '李四', 'age' => 17),
    array('nodeName' => 'person', 'name' => '王五', 'age' => 18),
    .......................
);
除 nodeName 外的键名称均为自定义名称。

2、根节点名称,可选参数,默认: root

演示 - 数组格式:

//实例化 XML
$xmlObj = new XmlClass();
//演示数据
$data = array(
    array('nodeName' => 'person', 'name' => '张三', 'age' => 16),
    array('nodeName' => 'person', 'name' => '李四', 'age' => 17),
    array('nodeName' => 'person', 'name' => '王五', 'age' => 18)
);
// 创建 XML
$xml = $xmlObj->create($data);
//保存 XML
file_put_contents('demo.xml', $xml);

演示 - 字符格式

$xmlObj = new XmlClass();
/*演示数据
$data = '	<person>
    <name>张三</name>
        <age>18</age>
    </person>
    <person>
        <name>李四</name>
        <age>18</age>
    </person>';
// 创建 XML
$xml = $xmlObj->create($data);


use Yll1024335892\Phptools\IpClass;
class indexController{
    public function index(){
        echo IpClass::getIp();
    }
}

$timer = new TimerClass();
echo $timer->currentYear();

$timer = new TimerClass();
echo $timer->currentMonth();

$timer = new TimerClass();
echo $timer->currentDay();

$timer = new TimerClass();
echo $timer->currentHour();

$timer = new TimerClass();
echo $timer->currentMin();

$timer = new TimerClass();
echo $timer->currentSecond();

参数:时间戳
演示:

$timer = new TimerClass();
echo $timer->fromTime($timer->timeStamp('2018-04-24 15:48:04'));


参数: xml 内容
演示:

$xmlObj = new XmlClass();
$xmlContent = file_get_contents('demo.xml');
$xml = $xmlObj->reader($xmlContent);
print_r($xml);

使用 phpGrace\tools\reflex 类的静态方法 r,参数:类或对象。


use Yll1024335892\Phptools\ReflexClass;
use Yll1024335892\Phptools\MailerClass;
class indexController{
    public function index(){
        $mailer  = new MailerClass();
        ReflexClass::r($mailer);
    }
}

文件位置 :
D:\web\localhost\yll1024335892\Phptools\MailerClass.php
属性 :
Property [ default private $mailConfig ]
类内常量 :
方法 :
Method [ user, ctor public method __construct ] { @@ D:\web\localhost\yll1024335892\Phptools\MailerClass.php 24 - 32 }
Method [ user public method send ] { @@ D:\web\localhost\yll1024335892\Phptools\MailerClass.php 34 - 77 - Parameters [4] ......

echo PinyinClass::getPinyin('您好!').'<br />';
//拼音首字母缩写
echo PinyinClass::getShortPinyin('您好!');

直接使用 NumToCapitalClass 类的静态方法 : ParseNumber()

echo NumToCapitalClass::ParseNumber(999158899.012);
//输出 玖亿玖仟玖佰壹拾伍万捌仟捌佰玖拾玖元零壹分