第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將 xml 節(jié)點(diǎn)附加到 php 中的另一個(gè)節(jié)點(diǎn)內(nèi)

將 xml 節(jié)點(diǎn)附加到 php 中的另一個(gè)節(jié)點(diǎn)內(nèi)

PHP
SMILET 2021-11-05 13:06:10
我想在節(jié)點(diǎn)內(nèi)插入不同的節(jié)點(diǎn)。但我不知道如何動(dòng)態(tài)地做到這一點(diǎn)我有這個(gè) xml 文件:<?xml version='1.0'  encoding='UTF-8'?><article artId="4686453" artName="UHOPI20190218-012A" Author="" Comment="" PubDate="2019-02-18" Section="country"> <head>    <headline>this is the title </headline>    <summary>        autor name @twitter    </summary>  </head> <body>    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer venenatis eleifend dui, at egestas sapien lobortis viverra.<!-- insert pullquotes here -->  </body><pullquote title="" catsList="" summary="" notes="" sectionColor="" sectionHead="">    Lorem ipsum dolor sit amet    <summary xml:space="preserve">Lorem ipsum dolor sit amet, consectetur adipiscing elit.    </summary>  </pullquote><pullquote title="" catsList="" summary="" notes="" sectionColor="" sectionHead="">    <headline xml:space="preserve">Some text</headline>    <summary xml:space="preserve">Some text</summary>    <summary xml:space="preserve">Some text</summary></pullquote></article>我試試這個(gè)……但它不起作用$xml = simplexml_load_file("files/test2.xml");$body = $xml->body;$pull1 = $xml->pullquote[0];$body->addChild($pull1);我想在節(jié)點(diǎn)內(nèi)插入每個(gè)節(jié)點(diǎn)我該怎么做?
查看完整描述

1 回答

?
UYOU

TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊

這是我的解決方案:


if($xmlData->body){

    $xmlIterator = new SimpleXMLIterator($xmlData->body->asXML());

    $xmlIterator->rewind();

    $txtBody = "";


    for($i=0; $i < ($xmlIterator->count()); $i++){

            $txtBody .= (trim($xmlIterator->current()) <> '') ? "<p>".trim($xmlIterator->current())."</p>" : "";

                            $xmlIterator->next();

                        }

                        #INSERT PULLQUOTE

                        foreach($xmlData->pullquote as $pull){

                            $txtBody .= $pull;


                            foreach ($pull->children() as $child){

                                $txtBody .= $child;

                            }


                        }


                        $data = $txtBody;

}


查看完整回答
反對(duì) 回復(fù) 2021-11-05
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)