php - 警告:在...中遇到的非数字值如何解决?
问题描述
当我在使用 PHP 7.2 的新服务器上迁移我的应用程序时,显示以下消息“警告:在...中遇到非数字值”
问题来自这一行(在以下代码的中间)
$out = $out + strpos($index, substr($in, $t, 1)) * $bcp;
。
如何解决?谢谢 !
public function alphaID($in, $to_num = false, $pad_up = false, $pass_key = null)
{
$out = '';
$index = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$base = strlen($index);
if ($pass_key !== null) {
// Although this function's purpose is to just make the ID short
for ($n = 0; $n < strlen($index); $n++) {
$i[] = substr($index, $n, 1);
}
$pass_hash = hash('sha256', $pass_key);
$pass_hash = (strlen($pass_hash) < strlen($index) ? hash('sha512', $pass_key) : $pass_hash);
for ($n = 0; $n < strlen($index); $n++) {
$p[] = substr($pass_hash, $n, 1);
}
array_multisort($p, SORT_DESC, $i);
$index = implode($i);
}
if ($to_num) {
// Digital number <<-- alphabet letter code
$len = strlen($in) - 1;
for ($t = $len; $t >= 0; $t--) {
$bcp = pow($base, $len - $t);
$out = $out + strpos($index, substr($in, $t, 1)) * $bcp;
}
if (is_numeric($pad_up)) {
$pad_up--;
if ($pad_up > 0) {
$out -= pow($base, $pad_up);
}
}
} else {
// Digital number -->> alphabet letter code
if (is_numeric($pad_up)) {
$pad_up--;
if ($pad_up > 0) {
$in += pow($base, $pad_up);
}
}
for ($t = ($in != 0 ? floor(log($in, $base)) : 0); $t >= 0; $t--) {
$bcp = pow($base, $t);
$a = floor($in / $bcp) % $base;
$out = $out . substr($index, $a, 1);
$in = $in - ($a * $bcp);
}
}
return $out;
}
解决方案
推荐阅读
- python - 烧瓶:sqlalchemy.exc.ProgrammingError:(psycopg2.errors.UndefinedColumn)列
- html - 滚动时jQuery元素位置绝对更改顶部
- python - Python:如何将 cookie 从 .txt 加载到 selenium 获取 webdriver 以登录到安全站点
- android - zxing 没有检测到条形码。可能的宽度/高度问题?
- java - 我想在基于 Java 的游戏中使用 RPI SenseHat 上的操纵杆作为输入
- javascript - 如何将字符串转换为毫秒?
- python - 当 CSV 仍在加载数据时,Python 调用错误(SQL 语句的参数不足)
- c# - 在 .net 核心上创建主机以在带有 topshelf 的 Windows 上用作服务
- google-app-engine - 为什么 GCP App 引擎的出口成本突然飙升?
- python - 计算另一列中重复数字的序列 - 熊猫