Jignasa Naik
Filed under - PHP
No Comments so far. Add yours now

Very good function for text spinning:

function spin($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 spin($s);
}

//Example:
echo spin(‘{This|Here} is {some|a {little|wee} bit of} {example|sample} text.’);

Tags: ,

Leave your comment

You must be logged in to post a comment.

Share IT © 2018. All rights reserved.