How to Read XML file and fetch values from it to display in PHP coded HTML page

后端 未结 2 1245
庸人自扰
庸人自扰 2021-01-29 10:53

I Have a XML file which have some repetitive tags containing different values into it. I need to fetch those values and display in in my webpage. Please help me up in getting th

2条回答
  •  清歌不尽
    2021-01-29 11:40

    Quite simply, you could do something like this:

    $raw = file_get_contents('path/to/xml/file.xml');
    
    $blankarray = array();
    
    $blank_xml = new SimpleXMLElement($raw);
    foreach($blank_xml->channel->item as $item) {
    $xml_item = array(
    'content' => $description,
    'date' => strtotime($item->pubDate),
    'type' => 'Whateva'
    );
    array_push($blankarray, $xml_item);
    }
    
    foreach($blankarray as $item) {
    echo '
  • ' . $item["content"] . '' . date(DATE_RFC822, $item["date"]) . '' . '
  • '; }

    Let me know if you have any questions.

提交回复
热议问题