好得很程序员自学网
  • 首页
  • 后端语言
    • C#
    • PHP
    • Python
    • java
    • Golang
    • ASP.NET
  • 前端开发
    • Angular
    • react框架
    • LayUi开发
    • javascript
    • HTML与HTML5
    • CSS与CSS3
    • jQuery
    • Bootstrap
    • NodeJS
    • Vue与小程序技术
    • Photoshop
  • 数据库技术
    • MSSQL
    • MYSQL
    • Redis
    • MongoDB
    • Oracle
    • PostgreSQL
    • Sqlite
    • 数据库基础
    • 数据库排错
  • CMS系统
    • HDHCMS
    • WordPress
    • Dedecms
    • PhpCms
    • 帝国CMS
    • ThinkPHP
    • Discuz
    • ZBlog
    • ECSHOP
  • 高手进阶
    • Android技术
    • 正则表达式
    • 数据结构与算法
  • 系统运维
    • Windows
    • apache
    • 服务器排错
    • 网站安全
    • nginx
    • linux系统
    • MacOS
  • 学习教程
    • 前端脚本教程
    • HTML与CSS 教程
    • 脚本语言教程
    • 数据库教程
    • 应用系统教程
  • 新技术
  • 编程导航
    • 区块链
    • IT资讯
    • 设计灵感
    • 建站资源
    • 开发团队
    • 程序社区
    • 图标图库
    • 图形动效
    • IDE环境
    • 在线工具
    • 调试测试
    • Node开发
    • 游戏框架
    • CSS库
    • Jquery插件
    • Js插件
    • Web框架
    • 移动端框架
    • 模块管理
    • 开发社区
    • 在线课堂
    • 框架类库
    • 项目托管
    • 云服务

当前位置:首页>后端语言>PHP
<tfoot draggable='sEl'></tfoot>

phpmath.min的简单介绍

很多站长朋友们都不太清楚phpmath.min,今天小编就来给大家整理phpmath.min,希望对各位有所帮助,具体内容如下:

本文目录一览: 1、 php如何把一个数分成N份 2、 php求助图片缩放裁切问题 3、 javascript里的Math.random() 函数, 在php里, 有类似的吗? 4、 怎么把如下php代码写成lua代码? 5、 php 计算经纬度之间相差多少公里 php如何把一个数分成N份

大致思路

1)取份数的平均值

2)根据允许的各份数间最大差值,动态调整随机数范围,形成各份的数量

3)最后一份的数量由前面已经分出的决定,以保证各份的总和为指定值

代码如下:

<?php

$total = 100; //待划分的数字

$div = 5; //分成的份数

$area = 10; //各份数间允许的最大差值

$average = round($total / $div);

$sum = 0;

$result = array_fill( 1, $div, 0 );

for( $i = 1; $i < $div; $i++ ){

 //根据已产生的随机数情况,调整新随机数范围,以保证各份间差值在指定范围内

 if( $sum > 0 ){

  $max = 0;

  $min = 0 - round( $area / 2 );

 }elseif( $sum < 0 ){

  $min = 0;

  $max = round( $area / 2 );

 }else{

  $max = round( $area / 2 );

  $min = 0 - round( $area / 2 );

 }

 //产生各份的份额

 $random = rand( $min, $max );

 $sum += $random;

 $result[$i] = $average + $random;

}

//最后一份的份额由前面的结果决定,以保证各份的总和为指定值

$result[$div] = $average - $sum;

//结果呈现

echo '划分情况:<br>';

foreach( $result as $temp ){

 echo $temp, '<br>';

}

echo '总和:', array_sum( $result );

exit;

?>

php求助图片缩放裁切问题

这段代码可以通过自已选择来决定图片的大小!

效果图如下所示:希望对你有帮助!

其中

minSize: [48,48],

setSelect: [0,0,190,190],

是调整选取范围的大小,若你 调整为120和160就改为了

setSelect: [0,0,120,160],

就可以了!

<?php

error_reporting(7);

date_default_timezone_set("Asia/Shanghai");

header("Content-type:text/html; Charset=utf-8");

require_once("./image.class.php");

$images = new Images("file");

if ($_GET['act'] == 'cut'){ 

 $image = "/data/upload/help/202303/13/ad7ffe963687c817362beb2b4764e277.jpg";

 $res = $images->thumb($image,false,1);

 if($res == false){

  echo "裁剪失败";

 }elseif(is_array($res)){

  echo '<img src="'.$res['big'].'" style="margin:10px;">';

  echo '<img src="'.$res['small'].'" style="margin:10px;">';

 }elseif(is_string($res)){

  echo '<img src="'.$res.'">';

 }

}elseif(isset($_GET['act'])  $_GET['act'] == "upload"){

 

 $path = $images->move_uploaded();

 $images->thumb($path,false,0);       //文件比规定的尺寸大则生成缩略图,小则保持原样

 if($path == false){

  $images->get_errMsg();

 }else{

  echo "上传成功!<a href='".$path."' target='_blank'>查看</a>";

 }

}else{

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ";quot;;>

<html>

 <head>

  <meta name="Author" content="SeekEver">

  <meta name="Keywords" content="">

  <meta name="Description" content="">

  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

  <script src="./js/jquery.min.js" type="text/javascript"></script>

  <script src="./js/jquery.Jcrop.js" type="text/javascript"></script>

  <link rel="stylesheet" href="./css/jquery.Jcrop.css" type="text/css" />

<script type="text/javascript">

  jQuery(function($){

    // Create variables (in this scope) to hold the API and image size

      var jcrop_api, boundx, boundy;

     

      $('#target').Jcrop({

  minSize: [48,48],

  setSelect: [0,0,190,190],

        onChange: updatePreview,

        onSelect: updatePreview,

  onSelect: updateCoords,

        aspectRatio: 1

      },

 function(){

        // Use the API to get the real image size

        var bounds = this.getBounds();

        boundx = bounds[0];

        boundy = bounds[1];

        // Store the API in the jcrop_api variable

        jcrop_api = this;

    });

 function updateCoords(c)

 {

  $('#x').val(c.x);

  $('#y').val(c.y);

  $('#w').val(c.w);

  $('#h').val(c.h);

 };

 function checkCoords()

 {

  if (parseInt($('#w').val())) return true;

  alert('Please select a crop region then press submit.');

  return false;

 };

      function updatePreview(c){

        if (parseInt(c.w) > 0)

        {

          var rx = 48 / c.w;  //小头像预览Div的大小

          var ry = 48 / c.h;

        $('#preview').css({

            width: Math.round(rx * boundx) + 'px',

            height: Math.round(ry * boundy) + 'px',

            marginLeft: '-' + Math.round(rx * c.x) + 'px',

            marginTop: '-' + Math.round(ry * c.y) + 'px'

          });

        }

     {

          var rx = 199 / c.w;  //大头像预览Div的大小

          var ry = 199 / c.h;

          $('#preview2').css({

            width: Math.round(rx * boundx) + 'px',

            height: Math.round(ry * boundy) + 'px',

            marginLeft: '-' + Math.round(rx * c.x) + 'px',

            marginTop: '-' + Math.round(ry * c.y) + 'px'

          });

        }

      };

    });

</script>

 </head>

 <body>

 <form method="post" action="?act=upload" enctype="multipart/form-data">

  <input type="file" name="file">

  <input type="submit" value="上传">

 </form>

 <div style="float:left;"><img id="target" src="/data/upload/help/202303/13/ad7ffe963687c817362beb2b4764e277.jpg"  ></div>

 <div style="width:48px;height:48px;margin:10px;overflow:hidden; float:left;"><img  style="float:left;" id="preview" src="/data/upload/help/202303/13/ad7ffe963687c817362beb2b4764e277.jpg" ></div>

 <div style="width:190px;height:195px;margin:10px;overflow:hidden; float:left;"><img  style="float:left;" id="preview2" src="/data/upload/help/202303/13/ad7ffe963687c817362beb2b4764e277.jpg" ></div>

 <form action="index.php?act=cut" method="post" onsubmit="return checkCoords();">

  <input type="hidden" id="x" name="x" />

  <input type="hidden" id="y" name="y" />

  <input type="hidden" id="w" name="w" />

  <input type="hidden" id="h" name="h" />

  <input type="submit" value="裁剪" />

 </form>

 </body>

</html>

<?php

} 

?>

javascript里的Math.random() 函数, 在php里, 有类似的吗?

<?php

function random($min = 0, $max = 1)

{

    return $min + mt_rand()/mt_getrandmax()*($max-$min);

}

var_dump(random());

// 打印结果

float 0.79857454579257

?>

怎么把如下php代码写成lua代码?

base64需要自己找个库调用一下,其他部分实现了,下面是代码

local function decode(str, skey)

   str = str or ""

   skey = skey or "cxphp"

   local replaceStr = string.gsub(str, "O0O0O", "=")

   replaceStr = string.gsub(replaceStr, "o000o", "+")

   replaceStr = string.gsub(replaceStr, "oo00o", "/")

   local strArr  = {}

   local replaceStrLen = string.len(replaceStr)

   for pos = 1, replaceStrLen, 2 do

      local posEnd = math.min(pos + 1, replaceStrLen)

      strArr [#strArr + 1] = string.sub(replaceStr, pos, posEnd)

    end

   local strCount = #strArr

   for key = 1, string.len(skey) do

      local value = string.sub(skey, key, key)

      print(key, value, strArr[key], string.sub(strArr[key], 2, 2))

      if key <= strCount and strArr[key] and string.sub(strArr[key], 2, 2) == value then

         strArr[key] = string.sub(strArr[key], 1, 1)

      end

   end

   local needToDecode = table.concat(strArr)

   print(needToDecode)

   -- TODO: find a lib base64_decode

end

php 计算经纬度之间相差多少公里

//php 计算地图上两个坐标之间的距离

define('EARTH_RADIUS', 6378.137);//地球半径,假设地球是规则的球体

define('PI', 3.1415926);

/**

* 计算两组经纬度坐标 之间的距离

* params :lat1 纬度1; lng1 经度1; lat2 纬度2; lng2 经度2; len_type (1:m or 2:km);

* return m or km

*/

function GetDistance($lat1, $lng1, $lat2, $lng2, $len_type = 1, $decimal = 2)

{

$radLat1 = $lat1 * PI ()/ 180.0; //PI()圆周率

$radLat2 = $lat2 * PI() / 180.0;

$a = $radLat1 - $radLat2;

$b = ($lng1 * PI() / 180.0) - ($lng2 * PI() / 180.0);

$s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1) * cos($radLat2) * pow(sin($b/2),2)));

$s = $s * EARTH_RADIUS;

$s = round($s * 1000);

if ($len_type --> 1)

{

$s /= 1000;

}

return round($s, $decimal);

}

echo GetDistance(39.908156,116.4767, 39.908452,116.450479, 1);//输出距离/米

关于phpmath.min的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。

查看更多关于phpmath.min的简单介绍的详细内容...

声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did208216
更新时间:2023-05-03   阅读:19次

上一篇: php整数转为字符串 php数字转字符串函数

下一篇:post本地php php提交post数据

相关资讯

最新资料更新

  • 1.php根据城市定位 php获取位置信息
  • 2.php函数rand PHP函数的参数传递包括
  • 3.php判断字符串的编码 php 判断字符串是否存在某个字符串
  • 4.php配置外网访问 phpstudy外网映射
  • 5.php代理访问源码 php 代理
  • 6.php登录保护机制 php保持登录状态
  • 7.php实现小说目录的方法 php自动生成小说
  • 8.php上传图片木马 php图片上传代码
  • 9.php仿应用商店 php android 应用
  • 10.登录htmlphp 登录html
  • 11.php时间戳转换字符串 php 时间戳转日期
  • 12.php如何接收对象 php怎么接收json数据
  • 13.phpisset多个值 php __set __get
  • 14.php换文字颜色 php文字颜色代码
  • 15.php比较运算符价格 php中用于比较字符串的函数
  • 16.php空间景安 php 免费空间
  • 17.php数据库对象 php针对数据库的查询函数是
  • 18.phpcurl解析失败 php在html中无法解析
  • 19.php数据库的建立 php中数据库怎么设计
  • 20.天津php公司的 天津程序员公司

CopyRight:2016-2025好得很程序员自学网 备案ICP:湘ICP备09009000号-16 http://haodehen.cn
本站资讯不构成任何建议,仅限于个人分享,参考须谨慎!
本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。
本网站刊载的所有内容(包括但不仅限文字、图片、LOGO、音频、视频、软件、程序等)版权归原作者所有。任何单位或个人认为本网站中的内容可能涉嫌侵犯其知识产权或存在不实内容时,请及时通知本站,予以删除。

网站内容来源于网络分享,如有侵权发邮箱到:kenbest@126.com,收到邮件我们会即时下线处理。
网站框架支持:HDHCMS   51LA统计 百度统计
Copyright © 2018-2025 「好得很程序员自学网」
[ SiteMap ]