-5
$bot = file_get_contents("http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=API_KEY&query=".$q1."");
echo $bot->Question[0]->ChosenAnswer;

For some reason, the script isn't returning anything.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • You are not using SimpleXML anywhere in that code. `file_get_contents` returns you a string. – gen_Eric Oct 23 '13 at 19:13
  • P.S. Don't add your API keys to the question. You should probably change it. – gen_Eric Oct 23 '13 at 19:15
  • I've asked many questions, but this is probably my stupidest. Anyways, thanks for your help. – I ain't smart. Oct 23 '13 at 20:14
  • *"For some reason"* - when asking a question, please share what the reason according to your understanding is and why you're not able to solve it your own. That creates more value with the question, otherwise it's just a dumping of code and "not working! help! heeeeeeeeeeeeeeeeeeeeeeelp!!!!" which is just for the trashcan. – hakre Oct 30 '13 at 08:50

1 Answers1

1

Firstly, you need to create instance of SimpleXML to use it.

$bot = file_get_contents("http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=API_KEY&query=".$q1."");
$bot = simplexml_load_string($bot);
echo $bot->Question[0]->ChosenAnswer;
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Andrey
  • 1,476
  • 1
  • 11
  • 17
  • 2
    I've asked many questions, but this is probably my stupidest. Anyways, thanks for your help. Sometimes the simple things take a while to figure out for me :\ – I ain't smart. Oct 23 '13 at 20:15