I am using the google translate class, and need to create a dynamic function name. what I have now is throwing an error: this is the error it is outputting: any recommendations?
you need a semi-colon after the "spannish" $language = "spannish"; //subject to dynamic change Also, it's Spanish (1 n)
$language = "spanish"; //subject to dynamic change $final_string = call_user_func(array($gt, "english_to_{$language}"), $value); PHP:
hey nico swd I plugged this in : and got this error message when trying to run. Does this have to do with $gt?
try doing this.... $language = "spannish" //subject to dynamic change eval('\$final_string = \$gt->enlgish_to_'.$language.'(\$value)'); that should give you what you want.
Stay away from eval() whenever possible. Try this: $language = "spanish"; //subject to dynamic change $function = "english_to_{$language}"; if (method_exists($gt, $function)) { $final_string = call_user_func(array($gt, "english_to_{$language}"), $value); } else { exit('Language not supported'); } PHP:
Hey guys, still no dice: throws this error: and tells me the language is not supported, and if I use the code: $c = $gt->english_to_spannish("$a"); I get results
Check the spelling. $language holds "spanish", and your function is called "spannish" (which is incorrect spelling, by the way). My first code should work just fine...
Your code works right, I just had to instantiate the $gt variable, I had not done it yet. final code: Thank you nico_swd!