全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 775|回复: 7

小白请教大佬,js函数转成php代码

[复制链接]
发表于 2020-9-10 23:23:19 | 显示全部楼层 |阅读模式
小白请教大佬,js函数转成php代码。

  1. function utf16to8(str) {
  2.     var out, i, len, c;

  3.     out = "";
  4.     len = str.length;
  5.     for(i = 0; i < len; i++) {
  6.         c = str.charCodeAt(i);
  7.         if ((c >= 0x0001) && (c <= 0x007F)) {
  8.             out += str.charAt(i);
  9.         } else if (c > 0x07FF) {
  10.             out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
  11.             out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
  12.             out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
  13.         } else {
  14.             out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
  15.             out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
  16.         }
  17.     }
  18.     return out;
  19. }
  20. var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  21. function base64encode(str) {
  22.     var out, i, len;
  23.     var c1, c2, c3;

  24.     len = str.length;
  25.     i = 0;
  26.     out = "";
  27.     while(i < len) {
  28.         c1 = str.charCodeAt(i++) & 0xff;
  29.         if(i == len)
  30.         {
  31.             out += base64EncodeChars.charAt(c1 >> 2);
  32.             out += base64EncodeChars.charAt((c1 & 0x3) << 4);
  33.             out += "==";
  34.             break;
  35.         }
  36.         c2 = str.charCodeAt(i++);
  37.         if(i == len)
  38.         {
  39.             out += base64EncodeChars.charAt(c1 >> 2);
  40.             out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  41.             out += base64EncodeChars.charAt((c2 & 0xF) << 2);
  42.             out += "=";
  43.             break;
  44.         }
  45.         c3 = str.charCodeAt(i++);
  46.         out += base64EncodeChars.charAt(c1 >> 2);
  47.         out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
  48.         out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
  49.         out += base64EncodeChars.charAt(c3 & 0x3F);
  50.     }
  51.     return out;
  52. }
复制代码
 楼主| 发表于 2020-9-10 23:24:42 | 显示全部楼层
可以付费,感谢大佬。
发表于 2020-9-10 23:26:44 | 显示全部楼层
发表于 2020-9-10 23:27:19 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2020-9-10 23:29:59 | 显示全部楼层
https://my.oschina.net/Jacker/blog/87170
拿走
发表于 2020-9-10 23:41:06 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2020-9-10 23:51:41 | 显示全部楼层
echo base64_encode("hostloc");
 楼主| 发表于 2020-9-11 00:42:20 | 显示全部楼层
感谢大佬们,已解决。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-3-29 06:20 , Processed in 0.059985 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表