php根据url输出二维码png

1、目录下放一个 phpqrcode.php即可

2、show.php如下

<?php
    
    $shell = "tail -n 50 /opt/xxqg/logs/logs.log";
    exec($shell, $result, $status);
    $shell = "<font color='red'>$shell</font>";
    //echo "<div style='line-height: 1;letter-spacing:-2.2px;'>";
    echo "<pre>";
    if( $status ){
        echo "shell命令{$shell}执行失败";
    } else {
        echo "shell命令{$shell}成功执行, 结果如下<hr> ";
     	$num = count($result); 
		for($i=0;$i<$num;++$i){
                        if( checkStr($result[$i] , '▄') || checkStr($result[$i] , '█') || checkStr($result[$i] , 'ALSA') ||
                            checkStr($result[$i] , 'Failed to query stereo recording') || $result[$i]==null ||checkStr( $result[$i] , '或')){
                            continue;
                        } 
			echo $result[$i].'<br />'; 
                        if( checkStr($result[$i] , 'login') ){
                             $qrimage = userimg($result[$i]);
                             echo '<img src='.$qrimage.'><br />';
                        }
		} 
    }
    echo "</pre></div>";




//$urlToEncode="http://www.helloweba.com";

//generateQRfromGoogle($urlToEncode);
/**
 * google api 二维码生成【QRcode可以存储最多4296个字母数字类型的任意文本,具体可以查看二维码数据格式】
 * @param string $chl 二维码包含的信息,可以是数字、字符、二进制信息、汉字。
 不能混合数据类型,数据必须经过UTF-8 URL-encoded
 * @param int $widhtHeight 生成二维码的尺寸设置
 * @param string $EC_level 可选纠错级别,QR码支持四个等级纠错,用来恢复丢失的、读错的、模糊的、数据。
 *                            L-默认:可以识别已损失的7%的数据
 *                            M-可以识别已损失15%的数据
 *                            Q-可以识别已损失25%的数据
 *                            H-可以识别已损失30%的数据
 * @param int $margin 生成的二维码离图片边框的距离
 */
/**
function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')

{

    $chl = urlencode($chl);

    echo '<img src="https://my1.wangty.workers.dev/-----http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" alt="QR code" widhtHeight="'.$widhtHeight.'  " widhtHeight="'.$widhtHeight.'"/>';

}
*/


function checkStr($str,$str2){
    return strstr($str,$str2)?true:false;
}

//生成二维码
function userimg($url='https://www.baidu.com'){
    
    //引入phpqrcode类库文件
    require_once 'phpqrcode.php';

    $value = $url;        //二维码内容
    $errorCorrectionLevel = 'L';  //容错级别
    $matrixPointSize = 5;      //生成图片大小


    //设置二维码图片名称,以及存放的路径
    $filename = 'qrcode.png';

    //使用类库生成二维码
    QRcode::png($value, $filename , $errorCorrectionLevel, $matrixPointSize, 2);
    return $filename;
} 



?>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值