with below sentence,
{Please|Just} make this {cool|awesome|random} test sentence {rotate {quickly|fast} and random|spin and be random}
I need to create a random() function which will give below output:-
Please make this cool test sentence rotate fast and random.
OR
Just make this random test sentence spin and be random.
I'm not sure how will I do this.
I've tried below but didn't get result.
echo spinningFunction($str);
function spinningFunction($str)
{
$output = "";
$pattern = "/\[.*?\]|\{.*?\}/";
preg_match_all($pattern, $str, $match);
$arr = array_map(function($value){
return explode("|", $value);
}, $match[1]);
foreach($arr[0] as $adj)
foreach($arr[1] as $name)
$output.= "{$adj} make this {$name} test sentence<br />";
return $output;
}
any help please?
EDIT:-
function spinningFunction($str)
{
$str = preg_replace_callback('/(\{[^}]*)([^{]*\})/im', "spinningFunction", $str);
return $str;
}
Will someone help me to achieve an array like below from above sentence:-
Array
(
[0] => Array
(
[0] => {Please|Just}
[1] => {cool|awesome|random}
[2] => {rotate {quickly|fast} and random|spin and be random}
)
)