使用PHP读取带有HTML标记的XML文件

时间:2017-07-25 10:20:52

标签: php html arrays xml

我有一个XML文件,我必须在Wordpress中导入。 问题是我的标签与Wordpress不兼容。

首先,我用php加载我的XML:

$fichier = 'communiques.xml';
date_default_timezone_set('Europe/Paris');
$xml = simplexml_load_file($fichier);

使用foreach,更改我的标签。

我的问题:

我的内容"标签包含HTML标签。当我打印我的var时,我的内容HTML会返回很多数组。

[h3] => Lorem ipsum .... 
[p] => Array
    (
        [0] => SimpleXMLElement Object
            (
                [b] => Array
                    (
                        [0] => Lorem ipsum dolor
                        [1] => sit amet, consectetur
                        [2] => Tennis et padel
                        [3] => SimpleXMLElement Object
                            (
                                [br] => SimpleXMLElement Object
                                    (
                                    )

                            )

                        [4] => adipiscing elit. 
                        [5] => Praesent id   
                        [6] => lorem ac quam malesuada :
                        [8] => dapibus. Nunc posuere commodo lorem
                    )

                [br] => Array
                    (
                        [0] => SimpleXMLElement Object
                            (
                            )

                        [1] => SimpleXMLElement Object
                            (
                            )

                        [...]

                        [46] => SimpleXMLElement Object
                            (
                            )

                        [47] => SimpleXMLElement Object
                            (
                            )

                    )

                [i] => « Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent id lorem ac quam malesuada dapibus. Nunc posuere commodo lorem sed pretium. Aliquam malesuada placerat convallis. Vivamus sed orci eu ipsum congue tincidunt semper in justo. Nulla congue congue turpis at luctus. »
            )

        [1] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent id lorem ac quam malesuada dapibus.
    )

[img] => Array
    (
        [0] => SimpleXMLElement Object
            (
                [@attributes] => Array
                    (
                        [src] => uploads/folder/text_name.jpg
                        [alt] => 
                    )

            )

        [1] => SimpleXMLElement Object
            (
                [@attributes] => Array
                    (
                        [src] => uploads/folder/perspective_2.jpg
                        [alt] => 
                    )

            )
    )
)

如何在我的标签中显示我的内容(带有HTML标签):

<content:encoded><![CDATA[  My content here  ]]></content:encoded>

其余的工作!

1 个答案:

答案 0 :(得分:0)

问题解决了。我添加了

{{1}}

并删除&#34;编码&#34;来自我的XML文件。