【问题标题】:reading xml using php to replace in between tags使用php读取xml以替换标签之间
【发布时间】:2014-02-10 17:56:47
【问题描述】:

您好,我想知道如何正确使用 php。

  1. 加载 XML 文档
  2. 查找和替换文本
  3. 以新名称保存 xml

XML 数据在这里无法发布,原因不明。 http://pastebin.com/A3rDtwzp

我想在内容标签之间找到文本,并将其替换为当前年份,用于 xml 中的所有标签。

如果可以请指导我简单的方法谢谢。

谢谢!

【问题讨论】:

    标签: php xml


    【解决方案1】:

    加载 XML 文档

     <?php
        // Issues an E_STRICT error
        $doc = DOMDocument::loadXML('<root><node/></root>');
        echo $doc->saveXML();
        ?>
    

    查找和替换文本

    <?php 
    
    // The text string 
    $text = "The quick brown fox jumped over the lazy dog."; 
    
    // The word we want to replace 
    $oldWord = "brown"; 
    
    // The new word we want in place of the old one 
    $newWord = "blue"; 
    
    // Run through the text and replaces all occurrences of $oldText 
    $text = str_replace($oldWord , $newWord , $text); 
    
    // Display the new text 
    echo $text; 
    
    ?>
    

    答案为 3

    <?php
        $docfile = new DOMDocument( );
        $eleT = $docfile->createElement( 'Root' );
        $eleT->nodeValue = 'Hello XML World';
        $docfile->appendChild( $eleT );
        $docfile->save('MyXmlFile.xml');
    ?>
    

    【讨论】:

    • 我希望他们一起工作 :P 像打开 xml (pastebin.com/A3rDtwzp) 查找和替换文本并保存 thnx :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 2017-12-12
    • 2012-08-28
    相关资源
    最近更新 更多