1

I have I'm trying to get the "extract" node value from an xml file/url. Below is my code, but I'm not getting any output.

<?php
$url = "https://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&exintro=&explaintext=&titles=unix";
$xml = simplexml_load_file($url);

echo $xml->extract ;
?>

Any help would be greatly appreciated.

1 Answer 1

2

$xml->extract would work if the node was a direct child of the xml file.

After looking at the api response, I am able to get and display the extract node using the full path:

$url = "https://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&exintro=&explaintext=&titles=unix";
$xml = simplexml_load_file($url);
echo $xml->query->pages->page->extract ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.