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

i have a XML file that i must to import in Wordpress. The problem is that my tags are not compatible with Wordpress.

So first, i load my XML with php :

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

And with foreach, change my tags.

My problem :

My "content" tags contain HTML tags. When i print my var, my content HTML return lot of array.

[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] => 
                    )

            )
    )
)

How can i display simply my content in my tag (with HTML tags) :

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

The rest works !

doukong9982
doukong9982 对不起,错误的问题:-(收回。
3 年多之前 回复
duanmiaosi0150
duanmiaosi0150 嗯,我不明白......你认为“SimpleHTMLDOMParser”这一章可以帮助我吗?
3 年多之前 回复

1个回答



问题解决了。 我添加了</ p>

  [CDATA [...]] 
</ code> </ pre>

并从我的XML文件中删除了“encoded” 。</ p>
</ div>

展开原文

原文

Problem solved. I added

[CDATA[...]] 

and removed "encoded" from my XML file.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐