Hi I am using this function in PHP to create some spun content (using spintax). However, if the spintax contains $ (dollar signs) they are removed in the output.
function spintext($s){
preg_match('#\{(.+?)\}#is',$s,$m);
if(empty($m)) return $s;
$t = $m[1];
if(strpos($t,'{')!==false){
$t = substr($t, strrpos($t,'{') + 1);
}
$parts = explode("|", $t);
$s = preg_replace("+\{".preg_quote($t)."\}+is", $parts[array_rand($parts)], $s, 1);
return spintext($s);
}
$out = spintext("Spinning a dollar sign: {$200|$400|$300}");
echo $out;
Results in:
Spinning a dollar sign: 0
Can anyone advise why this might be? Also, can you see any areas where the efficiency of this code might be improved to speed up the spin process and reduce memory usage?