سؤال

This PHP snippet isn't working:

<?php
$fille = simplexml_load_file("http://answers.yahooapis.com/AnswersService/V1/getQuestion?appid=dj0yJmk9OFRTTUI3NGdNNjREJmQ9WVdrOU5FZFBURzFqTkdNbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1iYg--&question_id=20080617101425AAmo159")
echo $fille->Question->Answers->Answer[0]->Content[0];
?>

Its purpose is to parse this XML file, and to get the first answer's contents.

 http://answers.yahooapis.com/AnswersService/V1/getQuestion?appid=dj0yJmk9OFRTTUI3NGdNNjREJmQ9WVdrOU5FZFBURzFqTkdNbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1iYg--&question_id=20080617101425AAmo159

However, upon runtime I get this error:

Parse error: syntax error, unexpected T_ECHO in /home/content/76/10008776/html/trysearch.php on line 3

هل كانت مفيدة؟

المحلول

You forgot the ; at the end of your line.

<?php
$fille = simplexml_load_file("http://answers.yahooapis.com/AnswersService/V1/getQuestion?appid=dj0yJmk9OFRTTUI3NGdNNjREJmQ9WVdrOU5FZFBURzFqTkdNbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1iYg--&question_id=20080617101425AAmo159");
echo $fille->Question->Answers->Answer[0]->Content[0];
?>

More generally, when you face an error like Parse error: syntax error, unexpected XXX on line X, check what's right before the line in question, it's mostly because you forgot something :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top