0

I currently have a script (phpSysInfo) that checks my server information. They have provided a file called xml.php - when I load this file in the URL, the content of an .xml file is generated.

My question is, how can I get data from this file/URL with PHP?

I have tried using simpleXML, but it doesn't seems to can open a .php file. Therefore I am stuck.

1
  • Paste the code you have tried and "doesn't work." Commented Nov 1, 2011 at 19:33

1 Answer 1

2

You'd need to execute the PHP file. Doing file_get_contents('xml.php') will simply read the raw PHP code.

Something like:

ob_start();
include('xml.php');
$data = ob_get_clean();

$xml = new SimpleXML($data);

would do the trick. The include() will execute the PHP script. And the ob_* functions will capture its output for you, returning it into the $data variable.

Sign up to request clarification or add additional context in comments.

8 Comments

Using this, how can I then echo out data with PHP from the XML file? I don't quite understand. Sorry
This: ** ob_start(); include('phpsysinfo/xml.php'); $data = ob_get_clean(); $xml = new SimpleXML($data); print($xml);** Doesn't output anything. I need to know how to echo out specific XML strings / data
$xml will be an object. you can't just print it out. $data will have the raw xml generated by the file.
Sorry, didn't mean to say print $xml. When printing out $data, nothing happens.
echo strlen($xml); if that prints a number other than 0, you've got xml data and just aren't seeing it in the window. If it's zero, then your xml.php isn't outputting anything and you'll have to figure out why.
|

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.