0

My problem is that the code i post is returning 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);

\\
\\
?>
3
  • Your function is returning nothing Commented Nov 15, 2014 at 16:23
  • when i also try to return $responseXML after curl_close($c); again i get undefinded variable !. Commented Nov 15, 2014 at 16:24
  • 1
    return the variable: $responseXML in the function and assgin it in the index.php to $responseXML Commented Nov 15, 2014 at 16:27

1 Answer 1

1

You need to return the xml data which you get from your curl call.

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);

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

1 Comment

Works, thnx a lot ! and sorry for any inconvenance !.

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.