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 ?

5
  • The error message appears to be incomplete, can you pos the full error message? Commented Oct 18, 2016 at 15:32
  • Warning: file_get_contents(eur-lex.europa.eu/legal-content/FR/TXT/XML/…): in C:\UwAmp\www\afnor\test.php on line 5. Line 5 refers to my echo line. Commented Oct 18, 2016 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 Commented Oct 18, 2016 at 15:35
  • it returns : string '1' (length=1) so it is On. That is right ? Commented Oct 18, 2016 at 15:40
  • that is right. Strange error you are getting... try one of these methods perhaps? stackoverflow.com/questions/3938534/… Commented Oct 18, 2016 at 16:01

2 Answers 2

1

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

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

Comments

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 !

Comments

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.