phpspintax

Why does this PHP spintax code repeat identical iterations?


http://ronaldarichardson.com/2011/09/23/recursive-php-spintax-class-3-0/

I like this script, but it isn't perfect. If you use this test input case:

{This is my {spintax|spuntext} formatted string, my {spintax|spuntext} formatted string, my {spintax|spuntext} formatted string example.}

You can see that the result ALWAYS contains 3 repetitions of either "spintax" or "spuntext". It never contains 1 "spintax" and 2 "spuntext", for example.

Example:

This is my spuntext formatted string, my spuntext formatted string, my spuntext formatted string example.

To be truly random it needs to generate a random iteration for each spintax {|} block and not repeat the same selection for identical blocks, like {spintax|spuntext}.

If you look at comment #7 on that page, fransberns is onto something, however when using his modified code in a live environment, the script would repeatedly run in an infinite loop and eat up all the server memory. So there must be a bug there, but I'm not sure what it is.

Any ideas? Or does anyone know of a robust PHP spintax script that allows for nested spintax and is truly random?


Solution

  • Please check this gist, it is working (and it is far simpler than original code ..).