2

I'm trying to print the xml source content of a page from its url using this :

echo file_get_contents("http://eur-lex.europa.eu/legal-content/FR/TXT/XML/?uri=CELEX:32012R0823

However, an error message appears:

Warning: file_get_contents(http://eur-lex.europa.eu/legal-content/FR/TXT/XML/?uri=CELEX:32012R0823)

What is wrong please ? What is the best way to get the source XML ?

Clay
  • 4,700
  • 3
  • 33
  • 49
J.P.A
  • 95
  • 6
  • The error message appears to be incomplete, can you pos the full error message? – Clay Oct 18 '16 at 15:32
  • Warning: file_get_contents(http://eur-lex.europa.eu/legal-content/FR/TXT/XML/?uri=CELEX:32012R0823): in C:\UwAmp\www\afnor\test.php on line 5. Line 5 refers to my echo line. – J.P.A Oct 18 '16 at 15:33
  • 1
    Also check var_dump(ini_get("allow_url_fopen")); you might need to change this, otherwise you need to use PHP CURL – Johnny Oct 18 '16 at 15:35
  • it returns : string '1' (length=1) so it is On. That is right ? – J.P.A Oct 18 '16 at 15:40
  • that is right. Strange error you are getting... try one of these methods perhaps? http://stackoverflow.com/questions/3938534/download-file-to-server-from-url?rq=1 – Clay Oct 18 '16 at 16:01

2 Answers2

1

it could be blocked by header if you declared in source page try ob_start() function in the top of your page.

alwasan
  • 11
  • 1
0

My problem is solved ! My company's proxy was the responsible. To overpass it, I installed CNTLM (local proxy : command line tools). With this, you must update cntlm.ini with the company's proxy's information and run this command :

cntlm -I -f -c {path of cntlm.ini}

Then, the php script :

$aContext = array( 
            'http' => array( 
                            'proxy' => "localhost:{port(in cntlm.ini find 'listen', in my case it is 3128)}",  
                            'request_fulluri' => True, 
                            'userid'=>"{username}", 
                            'password'=>"{password}" 
                            )
            ); 

$context = stream_context_create($aContext); 

$content =  file_get_contents({your target url string}, 0, $context);  
echo $content;

I hope that it will help !

J.P.A
  • 95
  • 6