小编use*_*037的帖子

PHP - 无法将String解析为XML

我目前正在使用以下代码,但没有返回结果:

<?php   
    $url = 'http://myknowledge.org.uk/xml';
    $xml = new SimpleXMLElement(file_get_contents($url));
    foreach ($xml->item as $item) {
        $title = $item->title;
    }

    echo $title;    
?>
Run Code Online (Sandbox Code Playgroud)

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<item>
    <title>Apple</title>
    <notableFor>Fruit</notableFor>
    <wikiid>Apple</wikiid>
    <description>The apple is the pomaceous fruit of the apple tree, Malus domestica of the rose family. It is one of the most widely cultivated tree fruits, and the most widely known of the many members of genus Malus that are used by humans.</description>
    <img></img>
    <website></website>
    <translate>
        <de>Äpfel</de>
        <fr>pomme</fr>
        <it>mela</it>
        <es>manzana</es>
        <ru>??????</ru> …
Run Code Online (Sandbox Code Playgroud)

php xml simplexml

2
推荐指数
1
解决办法
4万
查看次数

标签 统计

php ×1

simplexml ×1

xml ×1