A
A
alestro2015-12-19 11:53:05
PHP
alestro, 2015-12-19 11:53:05

How to parse xml by url?

You need to parse the xml file. I do something like this:

$xml = simplexml_load_file('http://www.cbr.ru/scripts/XML_daily.asp?date_req=02/03/2002');
$xml = new SimpleXMLElement($xml);

And here is what I get as a result:
Warning: SimpleXMLElement::__construct(): Entity: line 19: parser error : Start tag expected, '<' not found in C:\OpenServer\domains\mvc-test\app\index. php on line 12
Warning: SimpleXMLElement::__construct(): in C:\OpenServer\domains\mvc-test\app\index.php on line 12
Warning: SimpleXMLElement::__construct(): ^ in C:\penServer\domains \mvc-test\app\index.php on line 12
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\OpenServer\domains\mvc-test\app\index.php: 12 Stack trace: #0 C:\OpenServer\domains\mvc-test\app\index.php(12): SimpleXMLElement->__construct('\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n...') #1 {main} thrown in C:\OpenServer\domains\mvc-test\app\index.php on line 12

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2015-12-19
@alestro

The second line must be erased, the first is enough

V
Valera Karmanov, 2015-12-19
@motokraft

<?php foreach( $xml->Valute as $node ): ?>
   <?php echo $node->Name.'<br>'; ?>
<?php endforeach; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question