dounielong7728 2014-03-21 12:14
浏览 46
已采纳

将变量拆分为定义的块数

I am trying to make my own password hash, which I thought I could use chunk_split() to split the string into two pieces. Apparantly I didn't understand the documentation!

Now, my question, is there a different way to split the string - PHP would be nice, other language is not a problem 'tough - into pieces of 3?

I do have other ideas, but this looks like the best way to me.

Jonathan

  • 写回答

2条回答 默认 最新

  • dongpa9277 2014-03-21 12:15
    关注

    I am trying to make my own password hash

    Don't try to roll out your own encryption scheme or hashing algorithm. If you're not an expert, there's many mistakes that you'll make. Why reinvent the wheel when are already many good solutions available on the Internet? If you're using PHP 5.x, then you can use the built-in solutions: password_hash() and password_verify()

    See: Cryptography — Why shouldn't we roll our own?


    However, if it's just for learning purposes, then you can use str_split() with the second parameter.

    Example:

    $str = 'foobarbaz';
    print_r(str_split($str, 3));
    

    Output:

    Array
    (
        [0] => foo
        [1] => bar
        [2] => baz
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭