Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用php编辑或替换xml字符串?_Javascript_Php_Xml_Xml Editor - Fatal编程技术网

Javascript 如何使用php编辑或替换xml字符串?

Javascript 如何使用php编辑或替换xml字符串?,javascript,php,xml,xml-editor,Javascript,Php,Xml,Xml Editor,我不得不把我的问题改成简单的问题 例如:我的XML文件名是:ABC.XML 此xml文件的内部是: <li class="thumb"><a class="Alibaba" href="google.com"></a></li> 所以,我的问题是: 如何使用PHP搜索ABC.xml中的字符串,找到Alibabaname并将其替换为AlibabaColorname并保存到ABC.xml 请指导我并给我举个例子。谢谢您您可以使用php和其他许多函

我不得不把我的问题改成简单的问题

例如:我的XML文件名是:ABC.XML

此xml文件的内部是:

<li class="thumb"><a class="Alibaba" href="google.com"></a></li>
  • 所以,我的问题是: 如何使用PHP搜索ABC.xml中的字符串,找到Alibabaname并将其替换为AlibabaColorname并保存到ABC.xml

    请指导我并给我举个例子。谢谢您

    您可以使用php和其他许多函数来实现这一点。这里有几个例子->

    如果XML已经在字符串中,您可以这样做

    PHP:

    xml.xml之后:

    <li>world</li>
    
  • 世界

  • 请记住将“用户名”更改为正确的用户名,或者如果您更愿意这样做,请使用FQDN。确保该文件也具有脚本写入的权限。

    通过如何在PHP中使用str_repalce()的声音,显示从何处获取此xmlsimple str_repalce()内容的代码?你能告诉我一个例子吗?它不起作用,先生。请参见我的编辑并相应地调整代码。你评论中的代码有一些大问题,你应该删除并复制我的最后一段代码。祝你好运,编程愉快!如果您满意,请将答案标记为正确
    <?php
        $xml = file_get_contents(/path/to/file); // or http://path.to/file.xml
        $myXmlString = str_replace('Alibaba', 'AlibabaColor', $xml);
    ?>
    
    <?php
        $xml = file_get_contents(/path/to/file); // or http://path.to/file.xml
        $myXmlString = str_replace('Alibaba', 'AlibabaColor', $xml);
        file_put_contents(/path/to/file, $myXmlString);
    ?>
    
    <li>hello</li>
    
    $file = '/home/username/public_html/xml.xml';
    $xml = file_get_contents($file);
    $text = str_replace('hello','world',$xml);
    file_put_contents($file, $text);
    
    <li>world</li>