douyan1896 2019-05-22 09:06
浏览 124
已采纳

替换DOM中的元素值

I want to save DOM tags value to exist XML, I found replace function but it is in js and I need the function in PHP

I tried save and saveXML function, but this didn't worked. I have tags in XML with colon "iaiext:auction_title". I used getElement and it's work good, next i cut title to 50 characters function work too, but how i can replace old title to this new title if i dont use path like simple_load_file. How to show in my script this path?


$dom = new DOMDocument;
$dom->load('p.xml');
$i = 0;
$tytuly = $dom->getElementsByTagName('auction_title');
foreach ($tytuly as $tytul){

    $title = $tytul->nodeValue;
    $end_title = doTitleCut($title);
    //echo "<pre>";
    //echo($end_title);
    //echo "<pre>";
    $i = $i+1;
}
  • 写回答

2条回答 默认 最新

  • dongyou7472 2019-05-22 09:41
    关注

    In your loop, you can update a particular nodes value the same way you fetch it - with nodeValue. So in your loop, just update it each time...

    $tytul->nodeValue = doTitleCut($title);
    

    Then after your loop, you can just echo the new XML out using

    echo $dom->saveXML();
    

    or save it using

    $dom->save("3.xml");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?