Using PHP file_get_contents with xml -


i'm not sure if xampp setup causing issue have got php page creating sample xml data seen below:

$xml = new simplexmlelement('<product/>'); $xml->addchild("price", "us dollars"); $xml->addchild("test","123123"); header("content-type: text/xml; charset=utf-8"); echo $xml->asxml(); 

this renders xml onscreen perfectly. when come read page using following:

$xml = simplexml_load_file("api.xml"); echo $xml->price; 

so have checked file firstly using file_get_contents("xml.php");

but returns php code rather output of code. have resolved using xml.php write file called feed.xml works fine wondering why file_get_contents("xml.php"); returned code rather parsed output. have used wrong method check file contents or setup issue xampp?

thank in advance.

the reason isn't working file_get_contents is:

...the preferred way read contents of file string.

it doesn't run php include response. you'd have either generate xml , use file_get_contents xml file or use php's curl function (as suggested).


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -