Use of cURL

I have type following code in my page, and am getting error a below. Please help.
error:Fatal error: Cannot redeclare simplexml_load_file() in /home/jawkqvwk/public_html/admin/curl.php on line 42

the code I typed:

<?php $ch = curl_init(""); $fp = fopen("example_homepage.html", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); $xml = simplexml_load_file('example_homepage.html'); print "
    \n"; foreach ($xml->channel->item as $item){ print "
  • $item->title
  • \n"; } print "
"; ?> <?php function simplexml_load_file($URL) { $ch = curl_init($URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $xml = simplexml_load_string(curl_exec($ch)); curl_close($ch); return $xml; } ?>

Let’s look at the error message.

Fatal error: Cannot redeclare simplexml_load_file() in /home/jawkqvwk/public_html/admin/curl.php on line 42

At line 42 you have tried declare a function called simplexml_load_file()

The error message tells you the function was already declared and cannot be declared again.

That fact that functions cannot be redeclared is documented at PHP Manual - User-defined functions

Thanks for your reply. But then what is the correct code?

Let’s look at the definition of declare.

“In programming languages, a declaration specifies the identifier, type, and other aspects of language elements such as variables and functions. It is used to announce the existence of the element to the compiler…”

So sit down and think about that error message again:

“Fatal error: Cannot redeclare simplexml_load_file()”


“Fatal error: Cannot announce the existence of simplexml_load_file() again”