INDEX

PHP - xml file - read(simplexml_load_file)

PHP XML - read file(simplexml_load_file)

(Source : test1.xml)
< ?xml version="1.0" encoding="utf-8"?>
< books>
  < book>
    < title>This is sample source.< /title>
    < contents>< ![CDATA[This book is good.]]>< /contents>
  < /book>
< /books>
-----------------------------------------
(PHP code)
< ?
$xml = "test1.xml";
$xmlData = simplexml_load_file($xml);

foreach ($xmlData->book as $book) {
    echo $book->title, '< br />';
    echo $book->contents, '< br />';
}
?>
-----------------------------------------
(Result)
This is sample source.
This book is good.

  


Copyright(c) 2007-2020 coding.dojeun.com All Rights Reserved.