简体   繁体   English

PHP文本改组和所有可能的选项

[英]PHP text shuffling and all possible options

Say I have a text string: {a|b|c|d} {a|b|c|d} {a|b|c|d} {a|b|c|d} . 假设我有一个文本字符串: {a|b|c|d} {a|b|c|d} {a|b|c|d} {a|b|c|d}

And simple PHP function to shuffle the text: 和简单的PHP函数可以将文本随机播放:

function fb_filter_shuffle($string)
{
    if(empty($string))
    {
        return NULL;
    }

    return preg_replace_callback('/\{.*?\}/i', function($m)
    {
        $options    = explode('|', mb_substr($m[0], 1, -1));

        shuffle($options);

        return current($options);
    }, $string);
}

I need to get all possible variations of the output. 我需要获取所有可能的输出变化。 But how? 但是如何? the only option I came up so far, was to run the code nnn times and pick the unique options. 到目前为止,我nnn的唯一选择是运行代码nnn次并选择唯一的选项。 Any more efficient suggestions? 还有更有效的建议吗?

30 seconds with Google and look what I came up with ;) 与Google一起30秒,看看我想出了什么;)

http://docstore.mik.ua/orelly/webprog/pcook/ch04_25.htm http://docstore.mik.ua/orelly/webprog/pcook/ch04_25.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM