So I have this PHP Class that basically spins text. What some people call spintax… But I want to use it in a Desktop application. Pretty new to Xojo, but have been doing PHP for years. Wondering is any people that are PHP and Xojo pros, have an idea of an efficient way to convert this for Desktop. While still be cross platform and not relying on anything Windows or MAC specific.
[code]class Spintax
{
public function process($text)
{
return preg_replace_callback(
‘/\{(((?>[^\{\}]+)|(?R))*)\}/x’,
array($this, ‘replace’),
$text
);
}
public function replace($text)
{
$text = $this->process($text[1]);
$parts = explode('|', $text);
return $parts[array_rand($parts)];
}
}[/code]
So basically what this does is you can feed it something like:
{quick|fast|large} Brown Fox Jumped Over The {Lazy|Sleepy|Passed Out {stupid|dumb|goofy}} Fox.
Then you might get a result like:
[quote]
large Brown Fox Jumped Over The Passed Out stupid Fox.
large Brown Fox Jumped Over The Lazy Fox.
fast Brown Fox Jumped Over The Lazy Fox.
fast Brown Fox Jumped Over The Passed Out goofy Fox.[/quote]
Basically it has a normal Spintax like: {quick|fast|large}
But it also has nested Spintax like: {Lazy|Sleepy|Passed Out {stupid|dumb|goofy}} Fox.
I know this is a rather odd thing, that most people probably wouldn’t have messed with before, but I figured I would ask.