我的问题是我发布的代码是返回Undefined variable $ responseXML
(curl.php)
<?php
function curl_seasson($url) {
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$responseXML = curl_exec($c);
curl_close($c);
}
?>
(的index.php)
<?php
$url = "site.xml.format";
require_once("curl.php");
curl_seasson($url);
$xml = simplexml_load_string($responseXML);
\\
\\
?>
答案 0 :(得分:1)
您需要返回从curl调用中获得的xml数据。
curl.php:
<?php
function curl_seasson($url) {
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$responseXML = curl_exec($c);
curl_close($c);
return $responseXML;
}
?>
的index.php:
<?php
$url = "site.xml.format";
require_once("curl.php");
$responseXML = curl_seasson($url);
$xml = simplexml_load_string($responseXML);
?>