Page 1 of 1

Calling Functions (displaying contents of) in another fx

Posted: Wed Jun 30, 2010 12:15 pm
by shanehunter
Hey Guys, Here's my code:

Code: Select all

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);
}


$spin2 = spin('{#1|#2|#3|#4|#5|#6|#7|#8|#9|#10|#11|#12|#13|#14|#15|#16|#17|#18|#19|#20}');

$speak = spin('{interesting|awesome|amazing|cool|informative|wierd|dope|wicked|neat|swell|inspiring|audacious|fullfilling|kickass|super cool} {site|page|article|link|file|place|zone|method|failure|success story|tactic}');
What I need to do is call the results of the $spin2 function (ie: #1, #2 etc) and the results of $speak (ie: interesting failure etc...) into a new function using the same spin code:

$awesome = $spin('{$spin2|$speak}');

so that $awesome will return either "#1" OR "awesome method" etc...

Right now, using the code above, I get a result returned of the actual function

ie: the echo is "$spin2" or "$speak" instead of the results OF the function.

Hopefully this makes sense, and hopefully someone can give me some useful code here.

Thanks ahead of time!!

Re: Calling Functions (displaying contents of) in another fx

Posted: Wed Jun 30, 2010 12:36 pm
by Jade
I *think* what you're trying to do is this but I could be totally wrong here:

Code: Select all

$result = spin("{" . spin($spin2) . "|" . spin($speak) . "}");

Re: Calling Functions (displaying contents of) in another fx

Posted: Wed Jun 30, 2010 12:54 pm
by shanehunter
Brilliant! Thanks so much jade!

Re: Calling Functions (displaying contents of) in another fx

Posted: Wed Jun 30, 2010 1:19 pm
by shanehunter
<nvrmnd> figured it out! thanks again!

Re: Calling Functions (displaying contents of) in another fx

Posted: Wed Jun 30, 2010 1:30 pm
by Jade

Code: Select all

$result = spin("{" . spin($spin2) . " | " . spin($speak) . " | " . spin($spin2) . " | " . spin($speak) . " | " . spin($spin2) . "}");