Calling Functions (displaying contents of) in another fx

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shanehunter
Forum Commoner
Posts: 30
Joined: Sun Jun 27, 2010 3:43 pm

Calling Functions (displaying contents of) in another fx

Post 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!!
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

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

Post 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) . "}");
shanehunter
Forum Commoner
Posts: 30
Joined: Sun Jun 27, 2010 3:43 pm

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

Post by shanehunter »

Brilliant! Thanks so much jade!
shanehunter
Forum Commoner
Posts: 30
Joined: Sun Jun 27, 2010 3:43 pm

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

Post by shanehunter »

<nvrmnd> figured it out! thanks again!
Last edited by shanehunter on Wed Jun 30, 2010 1:32 pm, edited 1 time in total.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

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

Post by Jade »

Code: Select all

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