function convert(input = "") {
    let pdst = input.toUpperCase().trim();
    let pit = [];
    let isg = "";
    while (/[0-9A-Z]+/.exec(pdst) !== null) {
        let data = /[0-9A-Z]+/.exec(pdst);
        if (data !== null) {
            let pd = data[0];
            let pdt = pd.length;
            if (/[0-9]+/.test(pd) && pd.length < 8) isg += pd;
            if (isg.length == 15) pd = isg;
            if (isg.length >= 15) isg = "";
            if (/[0-9]+/.test(pd) && pd.length == 11 && pd.substring(0, 1).toLowerCase() == "s") pit.push(pd.trim().substring(1, 11));
            if (/[0-9]+/.test(pd) && pd.length == 13 && pd.substring(0, 1).toLowerCase() == "s") pit.push(pd.trim().substring(1, 13));
            if ((/[0-9]+/.test(pd) && pd.length == 15) || pd.length == 12 || pd.length == 10 || (/[0-9]+/.test(pd) && pd.length == 8)) pit.push(pd);
            pdst = pdst.substring(pdt).trim();
        }
    }
    return Array.from(new Set(pit));
}
|      1phpfpm      2022-10-11 02:15:39 +08:00 via Android 直接 node 跑 | 
|  |      3flyqie      2022-10-11 07:13:40 +08:00 via Android 给个示例输入? | 
|  |      4snoopyhai      2022-10-11 08:50:59 +08:00 语法没有差太多,边查手册边翻译吧 | 
|      5ywmail      2022-10-11 08:55:33 +08:00  2 github copilot 转换的: ``` function convert($input = "") { $pdst = strtoupper(trim($input)); $pit = []; $isg = ""; while (preg_match_all("/[0-9A-Z]+/", $pdst) !== null) { $data = preg_match_all("/[0-9A-Z]+/", $pdst); if ($data !== null) { $pd = $data[0]; $pdt = strlen($pd); if (preg_match_all("/[0-9]+/", $pd) && strlen($pd) < 8) $isg .= $pd; if (strlen($isg) == 15) $pd = $isg; if (strlen($isg) >= 15) $isg = ""; if (preg_match_all("/[0-9]+/", $pd) && strlen($pd) == 11 && strtolower(substr($pd, 0, 1)) == "s") array_push($pit, substr($pd, 1, 10)); if (preg_match_all("/[0-9]+/", $pd) && strlen($pd) == 13 && strtolower(substr($pd, 0, 1)) == "s") array_push($pit, substr($pd, 1, 12)); if ((preg_match_all("/[0-9]+/", $pd) && strlen($pd) == 15) || strlen($pd) == 12 || strlen($pd) == 10 || (preg_match_all("/[0-9]+/", $pd) && strlen($pd) == 8)) array_push($pit, $pd); $pdst = substr($pdst, $pdt); } } return array_unique($pit); } ``` | 
|  |      6musi      2022-10-11 09:10:27 +08:00 不懂就问,这段代码的 node 并发干不过 php ? | 
|  |      10learningman      2022-10-11 10:49:04 +08:00  5 | 
|      13landers2015      2022-10-11 11:03:11 +08:00 @ywmail 你交了$了?还是有科学方式?求分享 | 
|  |      14zoharSoul      2022-10-11 11:19:39 +08:00 @learningman #10  怎么转的? | 
|      15wvD98ys9PyO2xEdV      2022-10-11 11:40:20 +08:00 @landers2015 可以上万能的 tb 不到 99rmb/年 | 
|      16wvD98ys9PyO2xEdV      2022-10-11 11:41:11 +08:00 @landers2015 GitHub 有学生包 里面有 github copilot 还有其他的 | 
|  |      17liuxu      2022-10-11 11:45:06 +08:00 两个半斤八两吧,是不是 js 的正则引擎跟不上,预编译缓存一下 | 
|  |      18helone      2022-10-11 12:50:09 +08:00 @musi node 中间还有一个 v8 引擎,php 的大部分代码其实是以 c 的形式在跑的,典型的场景就是图片验证码的生成,php 写出来的生成速度比 Go 还要快几倍 | 
|  |      20xxiu      2022-10-11 14:24:03 +08:00 https://models.aminer.cn/codegeex/zh-CN/codeTranslator function convert($input) { $pdst = strtoupper($input); $pit = array(); $isg = ""; while (preg_match("/[0-9A-Z]+/", $pdst, $matches)) { $data = $matches; if ($data) { $pdt = strlen($data[0]); if (strpos($data[0], "1") === 0 && strpos($data[0], "2") === strlen($data[0]) - 1) $isg = $data[0]; if (strpos($data[0], "1")!== 0 && strpos($data[0], "2")!== strlen($data[0]) - 1) $isg = ""; if (strpos($data[0], "1") === 0 && strpos($data[0], "2")!== strlen($data[0]) - 1) $isg = ""; if ($isg!== "") $pdst = substr($pdst, 0, strpos($pdst, $isg) - 1). $isg.substr($pdst, strlen($isg)); if (strpos($data[0], "1")!== 0 && strpos($data[0], "2") === strlen($data[0]) - 1) $pit[] = substr($pdst, 0, strpos($pdst, $data[0]) - 1).substr($pdst, strlen($data[0])); if (strpos($data[0], "1") === 0 && strpos($data[0], "2")!== strlen($data[0]) - 1) $pit[] = substr($pdst, 0, strpos($pdst, $data[0]) - 1); if (strpos($data[0], "1")!== 0 && strpos($data[0], "2")!== strlen($data[0]) - 1) $pit[] = substr($pdst, 0, strpos($pdst, $data[0]) - 1).substr($pdst, strlen($data[0])).substr($pdst, strpos($pdst, $data[0]) + strlen($data[0]) - strlen($pdst)); if (strpos($data[0], "1")!== 0 && strpos($data[0], "2") === strlen($data[0]) - 1) $pit[] = substr($pdst, 0, strpos($pdst, $data[0]) - 1).substr($pdst, strlen($data[0])).substr($pdst, strpos($pdst, $data[0]) + strlen($data[0]) - strlen($pdst)); $pdst = substr($pdst, $pdt); } } return $pit; } | 
|      21ForkGagHub      2022-10-11 15:17:08 +08:00 虽然我不会拍黄片,但是帮你找到了一个网站 https://wtools.io/javascript-to-php-converter <?php $var = 'function convert(input = "") { let pdst = input.toUpperCase().trim(); let pit = []; let isg = ""; while (/[0-9A-Z]+/.exec(pdst) !== null) { let data = /[0-9A-Z]+/.exec(pdst); if (data !== null) { let pd = data[0]; let pdt = pd.length; if (/[0-9]+/.test(pd) && pd.length < 8) isg += pd; if (isg.length == 15) pd = isg; if (isg.length >= 15) isg = ""; if (/[0-9]+/.test(pd) && pd.length == 11 && pd.substring(0, 1).toLowerCase() == "s") pit.push(pd.trim().substring(1, 11)); if (/[0-9]+/.test(pd) && pd.length == 13 && pd.substring(0, 1).toLowerCase() == "s") pit.push(pd.trim().substring(1, 13)); if ((/[0-9]+/.test(pd) && pd.length == 15) || pd.length == 12 || pd.length == 10 || (/[0-9]+/.test(pd) && pd.length == 8)) pit.push(pd); pdst = pdst.substring(pdt).trim(); } } return Array.from(new Set(pit)); } | 
|  |      22l9rw      2022-10-11 15:26:11 +08:00 楼上工具转出来的代码第五行的判断都是错的 | 
|      24Austaras      2022-10-11 16:27:24 +08:00 你真要并发的话不如在 node 里面开个 worker ,反正都是原生数据类型 | 
|  |      25Light3      2022-10-11 16:31:11 +08:00 会写 php 但是 js 会的不多 没看懂楼主接了个字符串 为什么要循环字符串.. 给楼主指一下 如何快速写出来 字符串 用 str_split() 分成数组 然后 foreach($list as $k=>$v){ } 循环 在循环里面 $k+1 就是字符串的第几位 然后判断 php 字符串 拼接值 +. 就可以 数组 直接[] 赋值就可以 php 正则函数 preg_match() 如果纯判断数字 is_numeric() 也可以 自己试试吧 | 
|  |      26zjsxwc      2022-10-11 17:01:46 +08:00 直接用这个 php 写的 js 解释器,在 php 里面运行 js https://github.com/hiltonjanfield/js4php5 | 
|      27wuxiaoqing234      2022-10-11 17:36:50 +08:00 @zjsxwc  你搞这个还得看入参和出参, 还不如直接看语法.. | 
|      28ywmail      2022-10-12 08:57:39 +08:00 @Marinaaaa @iddddg @kamal  copilot 还有另一个 vs code 插件:github copilot labs ,用它转的。 @landers2015 折腾了一圈替代品,发现和 copilot 差距太大,最后交了$买的。 | 
|      29Chaningnt      2022-10-12 16:00:00 +08:00  1 测试了两三条数据 function convert($input){ $pdst = trim(strtoupper($input)); $isg = ''; $pit = []; while (preg_match('/[0-9A-Z]+/', $pdst, $data) != false){ if(count($data) > 0){ $pd = $data[0]; $pdt = strlen($pd); if(preg_match('/[0-9]+/', $pd) && strlen($pd) < 8 ){ $isg .= $pd; } if(strlen($isg) == 15){ $pd = $isg; } if(strlen($isg) >= 15){ $isg = ''; } if(preg_match('/[0-9]+/', $pd) && strlen($pd) == 11 && substr($pd, 0, 1) == 's'){ $pit[] = substr(trim($pd), 1, 11); } if(preg_match('/[0-9]+/', $pd) && strlen($pd) == 13 && substr($pd, 0, 1) == 's'){ $pit[] = substr(trim($pd), 1, 13); } if((preg_match('/[0-9]+/', $pd) && strlen($pd) == 15) || strlen($pd) == 12 || strlen($pd) == 10 || (preg_match('/[0-9]+/', $pd) && strlen($pd) == 8)){ $pit[] = $pd; } $pdst = trim(substr($pdst, $pdt)); } } return $pit; } | 
|      31Chaningnt      2022-10-12 16:26:50 +08:00  1 按 js 的格式处理了一下 function convert($input){ $pdst = trim(strtoupper($input)); $isg = ''; $pit = []; while (preg_match('/[0-9A-Z]+/', $pdst, $data) != false){ if(count($data) > 0){ $pd = $data[0]; $pdt = strlen($pd); if(preg_match('/[0-9]+/', $pd) && strlen($pd) < 8 ) $isg .= $pd; if(strlen($isg) == 15) $pd = $isg; if(strlen($isg) >= 15) $isg = ''; if(preg_match('/[0-9]+/', $pd) && strlen($pd) == 11 && substr($pd, 0, 1) == 's') $pit[] = substr(trim($pd), 1, 11); if(preg_match('/[0-9]+/', $pd) && strlen($pd) == 13 && substr($pd, 0, 1) == 's') $pit[] = substr(trim($pd), 1, 13); if((preg_match('/[0-9]+/', $pd) && strlen($pd) == 15) || strlen($pd) == 12 || strlen($pd) == 10 || (preg_match('/[0-9]+/', $pd) && strlen($pd) == 8)) $pit[] = $pd; $pdst = trim(substr($pdst, $pdt)); } } return array_unique($pit); } |